package org.jeecg.modules.gwcjava.jiekou.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.config.Swagger2Config;
import org.jeecg.modules.ParameterModule.entity.AddSystemPriceInfo;
import org.jeecg.modules.gwcjava.jiekou.entity.*;
import org.jeecg.modules.gwcjava.jiekou.service.BusinessLogicService;
import org.jeecg.modules.gwcjava.jiekou.service.MlccUserInfoService;
import org.jeecg.modules.shiro.vo.DefContants;
import org.jeecg.modules.zonglzp.entity.BusinesswaterEntity;
import org.jeecg.modules.zonglzp.util.WordUtils;
import org.jeecg.util.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

import static java.lang.System.getProperties;
import static org.jeecg.common.constant.CommonConstant.category_sex_nan;
import static org.jeecg.common.constant.CommonConstant.category_sex_nv;

/**
 * 前端接口处理
 * */
@Api(tags="web端接口")
@RestController
@RequestMapping("/logic/interface")
@Slf4j
public class BusinessLogiController {
    @Autowired
    private BusinessLogicService logicService;
    /**查询用户信息*/
    @Autowired
    private MlccUserInfoService userservice;
    /**添加日志*/
    @Autowired
    private ISysBaseAPI sysBaseAPI;

    /**
     * 产品求购
     * @param
     * @return boolean
     */
    @PostMapping(value = "/looking_products")
    @ResponseBody
    public JSONObject post_looking_products(String token,String looking_title,String looking_detail,String imgs) {
        //根据前端传入的值返回json数据
        JSONObject obj = new JSONObject();//返回对象
        try {
            if(looking_title==null || "".equals(looking_title)){
                obj.put("code", 1);
                obj.put("msg", "求购标题不能为空");
                return obj;
            }
            if(looking_detail==null || "".equals(looking_detail)){
                obj.put("code", 2);
                obj.put("msg", "求购内容不能为空");
                return obj;
            }
            if(token==null || "".equals(token)){
                obj.put("code", 3);
                obj.put("msg", "token为空，请重新登录获取");
                return obj;
            }
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(token,3);
            if(userInfo==null){
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            int code = logicService.add_looking(userInfo.getId().toString(),looking_title,looking_detail,imgs,new Date());
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "求购成功");
                return obj;
            }else {
                obj.put("code", 5);
                obj.put("msg", "求购失败");
                return obj;
            }
        }catch (Exception e){
            obj.put("code", 6);
            obj.put("msg", "参数错误");
            return obj;
        }
    }

    /**
     * 个订的导航栏模块
     * @return
     */
    @PostMapping(value = "/query_module")
    public JSONObject post_query_module(ServletRequest request) {
//        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
//        String token = httpServletRequest.getHeader(DefContants.X_ACCESS_TOKEN);
//        System.out.print("头部的token=="+token);
        JSONObject obj = new JSONObject();//返回对象
        List<ModelInfo> detailinfo = logicService.query_module();
        if(detailinfo!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", detailinfo);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
        }
    }
    /**
     * 根据公司id查询所有门店
     * @return
     */
    @PostMapping(value = "/query_allstore_companyId")
    public JSONObject query_allstore_companyid(String token){
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token,3);
        if(userInfo==null){
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        if(userInfo.getIdentity()==2){
            if(userInfo.getCompanyId()!=null || !"".equals(userInfo.getCompanyId())){
                List<StoreInfo> storeinfo = logicService.query_storeinfo(userInfo.getCompanyId(),2);
                if(storeinfo!=null){
                    obj.put("code", 0);
                    obj.put("msg", "查询成功");
                    obj.put("data", storeinfo);
                    return obj;
                }else {
                    obj.put("code", 1);
                    obj.put("msg", "查询失败");
                    return obj;
                }
            }else {
                obj.put("code", 2);
                obj.put("msg", "该账户暂无绑定公司");
                obj.put("data", "");
                return obj;
            }
        }else {//非公司
            List<StoreInfo> storeinfo = logicService.query_storeinfo(userInfo.getStoreId(),1);
            if(storeinfo!=null){
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", storeinfo);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "查询失败");
                return obj;
            }
        }
    }
    /**
     * 根据门店编码查询门店信息
     * @return
     */
    @PostMapping(value = "/query_storeinfoBycode")
    public JSONObject queryreceiveOrderlist(String store_code){
        JSONObject obj = new JSONObject();//返回对象
            StoreInfo storeinfo = logicService.query_storeDetailBycode(store_code);
            if(storeinfo!=null){
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", storeinfo);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "查询失败");
                return obj;
            }
    }

    /**
     * 根据门店编码查询门店的常用地址
     * @return
     */
    @PostMapping(value = "/query_storeAddressBycode")
    public JSONObject query_storeAddressBycode(String token){
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        List<StoreInfo> storeinfo = logicService.query_storeAddressBycode(userInfo.getCompanyOrgcode());
        if(storeinfo!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", storeinfo);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
        }
    }

    /**
     * 根据常用地址id查询地址详情
     * @return
     */
    @PostMapping(value = "/query_nomladdressById")
    public JSONObject query_nomladdressById(String address_id){
        JSONObject obj = new JSONObject();//返回对象
        StoreInfo storeinfo = logicService.query_nomladdressByid(address_id);
        if(storeinfo!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", storeinfo);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
        }
    }

    /**
     * 根据传入的type查询不同数据类型值
     * @return
     */
    @PostMapping(value = "/query_dataBytype")
    public JSONObject post_query_dataBytype(String type){
        JSONObject obj = new JSONObject();//返回对象
        List<DataTypeInfo> datalist = logicService.query_dataBytype(type);
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
        }
    }
    /**
     * 查询所有的快递
     * @return
     */
    @PostMapping(value = "/query_allCourier")
    public JSONObject post_query_allCourier() {
         JSONObject obj = new JSONObject();//返回对象
         List<CourierInfo> datainfo = logicService.query_AllCourier();
         if(datainfo!=null){
             obj.put("code", 0);
             obj.put("msg", "查询成功");
             obj.put("data", datainfo);
             return obj;
         }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
         }
    }

    /**
     * 根据导航栏id和类别id查询模块名称
     * @return
     */
    @PostMapping(value = "/query_mstemplateinfo")
    public JSONObject post_query_mstemplateinfo(String module_id,String category_id){
        JSONObject obj = new JSONObject();//返回对象
        List<ModuleSmalltemplateInfo> datalist = logicService.query_SmalltemplateInfo(module_id,category_id);
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
        }
    }

    /**
     * 根据查询模块id和前面的类别ids查询类别
     * @return
     */
    @PostMapping(value = "/query_categoryinfo")
    public JSONObject post_query_categoryinfo(String template_id,String category_ids){
        JSONObject obj = new JSONObject();//返回对象
        List<CategoryInfo> datalist = new ArrayList<>();
        String categoryids[] = category_ids.split(",");
        if("1".equals(template_id)){
            //查询所有的性别
            for (String s:categoryids) {
                datalist = logicService.query_categoryInfo(template_id, s);
                if (datalist.size() > 0) {
                    break;
                } else {
                    continue;
                }
            }
        }else if("2".equals(template_id)){
            //查询所有的品类
            datalist = logicService.query_categoryInfo(template_id, categoryids[0]);
        }else if("3".equals(template_id)){
            //查询所有的版号
            datalist = logicService.query_categoryInfo(template_id, categoryids[1]);
        }else if("4".equals(template_id)){
            //查询所有的工艺
            datalist = logicService.query_categoryInfo(template_id, categoryids[2]);
        }
        if(datalist.size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /**
     * 查询全部的字体
     * @return
     */
    @PostMapping(value = "/query_AllembroiderFont")
    public JSONObject post_query_AllembroiderFont(String category_ids,int type) {
        JSONObject obj = new JSONObject();//返回对象
        List<EmbroideredFontInfo> datalist = new ArrayList<>();
        String categoryids[] = category_ids.split(",");
        for (String s:categoryids){
            datalist = logicService.query_AllembroiderFont(s,type);
            if(datalist.size()>0){
                break;
            }else {
                continue;
            }
        }
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
        }
    }

    /**
     * 查询全部的颜色
     * @return
     */
    @PostMapping(value = "/query_AllembroiderColor")
    public JSONObject post_query_AllembroiderColor(String category_ids) {
        JSONObject obj = new JSONObject();//返回对象
        List<EmbroideredColorInfo> datalist = new ArrayList<>();
        String categoryids[] = category_ids.split(",");
        for (String s:categoryids){
            datalist = logicService.query_AllembroiderColor(s);
            if(datalist.size()>0){
                break;
            }else {
                continue;
            }
        }
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
        }
    }

    /**
     * 查询全部的撞色
     * @return
     */
    @PostMapping(value = "/query_AllContrastcolorInfo")
    public JSONObject post_query_AllContrastcolorInfo(String category_ids) {
        JSONObject obj = new JSONObject();//返回对象
        List<ContrastcolorInfo> datalist = new ArrayList<>();
        String pinglei_id = "";//版号id
        String categoryids[] = category_ids.split(",");
        for (String s:categoryids){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==3){
                    pinglei_id = categoryInfo.getId().toString();
                    break;
                }
            }
        }
        datalist = logicService.query_AllContrastcolorInfo(pinglei_id,category_ids);

//        String categoryids[] = category_ids.split(",");
//        for (String s:categoryids){
//            datalist = logicService.query_AllContrastcolorInfo(s,category_ids);
//            if(datalist.size()>0){
//                break;
//            }else {
//                continue;
//            }
//        }
        if(datalist != null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
        }
        return obj;
    }


    /**
     * 查询绣字高度-根据品类id
     * @return
     */
    @PostMapping(value = "/query_xiuzi_heaight")
    public JSONObject query_xiuzi_heaight(String category_ids,String xiuziType) {
        JSONObject obj = new JSONObject();//返回对象
        List<EmbroideredTypePriceInfo> datalist = new ArrayList<>();
        String categoryids[] = category_ids.split(",");
        String pinglei_id = "";
        for (String s:categoryids){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==2){
                    pinglei_id = categoryInfo.getId().toString();
                    break;
                }
            }
        }
        datalist = logicService.query_xiuziHeightInfo(pinglei_id,xiuziType);
        if(datalist != null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
        }
        return obj;
    }

    /**
     * 修改撞色的色值
     * @return
     */
    @PostMapping(value = "/update_Contrastcolor_color")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_update_Contrastcolor_color(String token,String id,String color_id,String category_ids,String product_id){
        JSONObject obj = new JSONObject();//返回对象
       try {
           MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
           if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
           }
           //根据条件查询撞色记录表
           int code = 0;
           ZhuangseRedcordInfo zhuangseRedcordInfo = logicService.query_zhuangseRedcordById(id,userInfo.getId().toString(),category_ids,product_id);
           if(zhuangseRedcordInfo!=null){
               //执行修改
               code = logicService.update_ContrastcolorRedcord(color_id,id,userInfo.getId().toString(),category_ids,product_id);
           }else {
               //执行添加
               code = logicService.add_ContrastcolorRedcord(id,color_id,userInfo.getId().toString(),category_ids,product_id);
           }
           if(code>0){
               obj.put("code", 0);
               obj.put("msg", "修改色值成功");
               return obj;
           }else {
               obj.put("code", 1);
               obj.put("msg", "修改色值失败");
               return obj;
           }
       }catch (Exception e){
           obj.put("code", 2);
           obj.put("msg", "修改色值失败，请重新选择");
           return obj;
       }
    }

    /**
     * 根据查询模块id和类别id查询身体数据
     * @return
     */
    @PostMapping(value = "/query_bodySizeinfo")
    public JSONObject post_query_bodySizeinfo(String template_id,String category_ids,String is_jin){
        JSONObject obj = new JSONObject();//返回对象

        List<BodySizeInfo> datalist = new ArrayList<>();
        String categoryids[] = category_ids.split(",");
        String pinglei_id = "";
        for (String s:categoryids){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==3){
                    pinglei_id = categoryInfo.getId().toString();
                    break;
                }
            }
        }
        datalist = logicService.query_bodySizeinfo(template_id,pinglei_id,is_jin);

//        List<BodySizeInfo> datalist = new ArrayList<>();
//        String categoryids[] = category_ids.split(",");
//        for (String s:categoryids){
//            datalist = logicService.query_bodySizeinfo(template_id,s,is_jin);
//            System.out.print("跳出==="+s+"==="+datalist.size());
//            if(datalist.size()>0){
//                break;
//            }else {
//                continue;
//            }
//        }
        if(datalist != null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
        }
        return obj;
    }

    /**
     * 根据查询模块id和类别id查询身体部位数据
     * @return
     */
    @PostMapping(value = "/query_sizeinfo")
    public JSONObject post_query_sizeinfo(String template_id,String category_ids){
        JSONObject obj = new JSONObject();//返回对象
        List<SizeInfo> datalist = new ArrayList<>();
        String categoryids[] = category_ids.split(",");
        for (String s:categoryids){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==2 && categoryInfo.getIsSize()==1){
                    datalist = logicService.query_sizeInfo(template_id,s);
                    break;
                }
            }
//            if(datalist.size()>0){
//                break;
//            }else {
//                continue;
//            }
        }
        if(datalist.size()>0){
            for (int i=0;i<datalist.size();i++){
                List<SizeInfo1> datalist2 = logicService.query_sizeInfo1(datalist.get(i).getId().toString());
                datalist.get(i).setSmallSizeInfo(datalist2);
            }
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            return obj;
        }
    }

    /**
     * 保存个订模板--修改模板信息
     * @return
     */
    @PostMapping(value = "/save_sign_module")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_save_sign_module(TemplateRecordInfo templateInfo) {
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(templateInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            //根据用户id和模板编号查询产品列表
            List<ProductInfo> productInfos = logicService.query_productInfoBytemplateSn(userInfo.getId().toString(),templateInfo.getOrderSn());
            StringBuffer buf=new StringBuffer();
            String chanpinids="";
            String chanpinids2 = "";
            if(productInfos.size()>0){
                for (int i=0;i<productInfos.size();i++){
                    buf.append(productInfos.get(i).getId()+",");
                }
                chanpinids = buf.toString();
                chanpinids2 = chanpinids.substring(0,chanpinids.length()-1);
            }
            templateInfo.setChanpinIds(chanpinids2);
            templateInfo.setStatus(0);
            //赋值公司编码
            templateInfo.setCompanyCode(userInfo.getCompanyOrgcode());
            if(userInfo.getIdentity()==3){//身份：默认0普通用户，1店长，2公司，3特殊身份
                templateInfo.setIsModule(1);
            }else {
                templateInfo.setIsModule(0);
            }
            //更新模板
            int code = logicService.update_single_templateInfo(templateInfo);
//            /**
//             * 日志添加
//             * @param LogContent 内容
//             * @param logType 日志类型(0:操作日志;1:登录日志;2:定时任务)
//             * @param operatetype 操作类型(1:添加;2:修改;3:删除;)
//             */
//            sysBaseAPI.addLog("用户：" + userInfo.getUsername() + "更新了一个新模版！", 0, 2);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "保存模板成功");
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "保存模板失败");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "添加失败，重新添加");
            return obj;
        }
    }

    /**
     * 创建个订订单----暂时不用
     * @return
     */
    @PostMapping(value = "/save_sign_order")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_save_sign_order(SingleOrderInfo orderInfo) {
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(orderInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            //设置user_id
            orderInfo.setUserId(userInfo.getId().toString());
            //获取汉子的首字母
            WordUtils word = new WordUtils();
            String zimuname = word.getUpperCase(userInfo.getRealname(),false);
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(10000)+1;//为变量赋随机值1-99999999;
            String order_sn = "S"+zimuname+random+(startTs.toString());
            orderInfo.setOrderSn(order_sn);
            if(orderInfo.getOrderName()==null || "".equals(orderInfo.getOrderName())){
                orderInfo.setOrderName(new Date()+"订单");
            }
            //添加个订订单
            int code = logicService.add_signOrderInfo(orderInfo);
            System.out.println("用户id==="+userInfo.getId()+"==="+order_sn);
            /**
             * 日志添加
             * @param LogContent 内容
             * @param logType 日志类型(0:操作日志;1:登录日志;2:定时任务)
             * @param operatetype 操作类型(1:添加;2:修改;3:删除;)
             */
            sysBaseAPI.addLog("用户：" + userInfo.getUsername() + "新建了一个个订订单！", 0, 1);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "订单生成成功");
                obj.put("order_sn", order_sn);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "订单生成失败");
                obj.put("order_sn", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "添加失败，请重新添加");
            obj.put("order_sn", "0");
            return obj;
        }
    }

    /**
     * 根据查类别id查询绣字位置表
     * @return
     */
    @PostMapping(value = "/query_localtion")
    public JSONObject post_query_localtion(String category_ids){
        JSONObject obj = new JSONObject();//返回对象
        List<CategoryLocaltion> datalist = new ArrayList<>();
        String categoryids[] = category_ids.split(",");
        for (String s:categoryids){
            datalist = logicService.query_localtionInfo(s);
            if(datalist.size()>0){
               break;
            }else {
               continue;
            }
        }
        if(datalist.size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /**
     * 根据用户id和type查询编辑中的订单或者模板
     * @return
     */
    @PostMapping(value = "/query_orderlistBytype")
    public JSONObject post_query_orderByuserId(@RequestParam(name="token") String token,
                                               @RequestParam(name="type") int type,
                                               @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                               @RequestParam(name="pageNo", defaultValue="1") Integer pageNo) {
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        //type:1查询订单，2查询我的模板，3查询明朗云模板
        if(type==1){
            Page<TemplateRecordInfo> page = new Page<TemplateRecordInfo>(pageNo, pageSize);
            IPage<TemplateRecordInfo> pageList = logicService.query_orderinfoByuserId(page,userInfo.getId().toString());
            if(pageList != null){
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", pageList);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "暂无数据");
                obj.put("data", pageList);
                return obj;
            }
        }else {
            Page<TemplateRecordInfo> page = new Page<TemplateRecordInfo>(pageNo, pageSize);
            IPage<TemplateRecordInfo> pageList = logicService.query_signmoduleinfo(page,userInfo.getCompanyOrgcode(),type);
            if(pageList != null){
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", pageList);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "暂无数据");
                obj.put("data", pageList);
                return obj;
            }
        }
    }

    /**
     * 根据用户id查询订单列表
     * @return
     */
    @PostMapping(value = "/query_myorderlist")
    public JSONObject post_query_myorderlist(@RequestParam(name="token") String token,
                                               @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                               @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                               String queryTime, String queryName) {
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        Page<SingleOrderInfo> page = new Page<SingleOrderInfo>(pageNo, pageSize);
        IPage<SingleOrderInfo> pageList = logicService.query_orderinfoByuserId2(page,userInfo.getOrgCode(),queryTime,queryName);
        if(pageList != null){
             obj.put("code", 0);
             obj.put("msg", "查询成功");
             obj.put("data", pageList);
             return obj;
        }else {
             obj.put("code", 1);
             obj.put("msg", "暂无数据");
             obj.put("data", pageList);
             return obj;
        }
    }
    /**
     * 修改状态--删除模板/订单
     * @return
     */
    @PostMapping(value = "/deleteBytype")
    public JSONObject post_update_status(String token,String order_sn,int type){
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        //type:1个订模板，2个订订单，3团队模板，4团订订单,5删除产品，此时的order_sn为产品id
        int code = logicService.update_status(order_sn,type);
        if(code>0){
            obj.put("code", 0);
            obj.put("msg", "删除成功");
        }else {
            obj.put("code", 1);
            obj.put("msg", "删除失败");
        }
        return obj;
    }

    /**
     * 创建个订订单的同时创建产品--再创建模板
     * @return
     */
    @PostMapping(value = "/create_sign_order")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_create_sign_order(SingleOrderInfo orderInfo) {
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(orderInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            /**订单信息*/
            //获取汉子的首字母
            WordUtils word = new WordUtils();
            String zimuname = word.getUpperCase(userInfo.getRealname(),false);
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //8位随机数
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            //订单编号
            String order_sn = "S"+zimuname+random+(startTs.toString());
            orderInfo.setOrderSn(order_sn);
            orderInfo.setUserId(userInfo.getId().toString());
            if(orderInfo.getOrderName()==null || "".equals(orderInfo.getOrderName())){
                orderInfo.setOrderName(f.format(new Date())+"订单");
            }
            /**模板信息*/
            TemplateRecordInfo templateRecordInfo = new TemplateRecordInfo();
            //8位随机数
            int random3=new Random().nextInt(10000000)+1;//为变量赋随机值1-99999999;
            //模板编号
            String template_sn = "SINGLEMB"+random3+(startTs.toString());
            templateRecordInfo.setOrderSn(template_sn);
            templateRecordInfo.setUserId(userInfo.getId().toString());
            if(templateRecordInfo.getTemplateName()==null || "".equals(templateRecordInfo.getTemplateName())){
                templateRecordInfo.setTemplateName(f.format(new Date())+"模板");
            }
            /**产品信息*/
            ProductInfo productInfo = new ProductInfo();
            if(productInfo.getProductName()==null || "".equals(productInfo.getProductName())){
                productInfo.setProductName(f.format(new Date())+"产品");
            }
            //8位随机数
            int random2=new Random().nextInt(100000000)+1;//为变量赋随机值1-99999999;
            String productSn = zimuname+(startTs.toString());
            String productId = startTs.toString()+random2;
            //赋值产品货号
            productInfo.setProductCode(productSn);
            //赋值产品id
            productInfo.setId(productId);
            //赋值用户id
            productInfo.setUserId(userInfo.getId().toString());
            //产品类型
            productInfo.setProductType(0);
            //赋值订单编号
            productInfo.setOrderSn(order_sn);
            //赋值模板编号
            productInfo.setTemplateSn(template_sn);
            //为订单赋值产品id
            orderInfo.setChanpingIds(productId);
            orderInfo.setStatus(0);
            orderInfo.setSysOrgCode(userInfo.getOrgCode());
            //为模板赋值产品id
            templateRecordInfo.setChanpinIds(productId);
            templateRecordInfo.setStatus(1);
            templateRecordInfo.setCompanyCode(userInfo.getCompanyOrgcode());
            templateRecordInfo.setSysOrgCode(userInfo.getOrgCode());
            //创建个订订单
            int code = logicService.add_signOrderInfo(orderInfo);
            //创建产品
            int code2 = logicService.insert_products(productInfo);
            //创建模板
            int code3 = logicService.add_templateInfo(templateRecordInfo);
            if(code>0 && code2>0 && code3>0){
                obj.put("code", 0);
                obj.put("msg", "创建订单模板产品成功");
                obj.put("order_sn", order_sn);
                obj.put("template_sn", template_sn);
                obj.put("productId", productId);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "创建失败");
                obj.put("order_sn", "0");
                obj.put("template_sn", "0");
                obj.put("productId", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "创建失败，请重新创建");
            return obj;
        }
    }

    /**
     * 根据订单号编辑
     * @return
     */
    @PostMapping(value = "/update_single_order")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_update_order(SingleOrderInfo orderInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(orderInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            if (orderInfo.getOrderSn() == null || "".equals(orderInfo.getOrderSn())) {
                obj.put("code", 2);
                obj.put("msg", "订单编号不能为空");
                return obj;
            }
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(orderInfo.getOrderName()==null || "".equals(orderInfo.getOrderName())){
                orderInfo.setOrderName(f.format(new Date())+"订单");
            }
            //根据用户id和模板编号查询产品列表
            List<ProductInfo> productInfos = logicService.query_productInfoByorderSn(userInfo.getId().toString(),orderInfo.getOrderSn());
            StringBuffer buf=new StringBuffer();
            String chanpinids="";
            String chanpinids2 = "";
            if(productInfos.size()>0){
                for (int i=0;i<productInfos.size();i++){
                    buf.append(productInfos.get(i).getId()+",");
                }
                chanpinids = buf.toString();
                chanpinids2 = chanpinids.substring(0,chanpinids.length()-1);
            }
            orderInfo.setChanpingIds(chanpinids2);

            //根据订单号修改订单
            int code = logicService.update_single_order(orderInfo);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "订单更新成功");
                obj.put("order_sn", orderInfo.getOrderSn());
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "订单更新失败");
                obj.put("order_sn", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "更新失败，请重新创建");
            obj.put("order_sn", "0");
            return obj;
        }
    }

    /**
     * 在订单下新建产品---暂不用
     * @return
     */
    @PostMapping(value = "/insert_products")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_insert_products(ProductInfo productInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(productInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            if(productInfo.getOrderSn()==null || "".equals(productInfo.getOrderSn())){
                obj.put("code", 6);
                obj.put("msg", "订单编号为空，保存或更新失败");
                return obj;
            }
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(productInfo.getProductName()==null || "".equals(productInfo.getProductName())){
                productInfo.setProductName(f.format(new Date())+"产品");
            }
            //获取汉子的首字母
            WordUtils word = new WordUtils();
            String zimuname = word.getUpperCase(userInfo.getRealname(),false);
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(10000000)+1;//为变量赋随机值1-99999999;
            String productSn = zimuname+(startTs.toString());
            String productId = startTs.toString()+random;
            //赋值产品货号
            productInfo.setProductCode(productSn);
            //赋值产品id
            productInfo.setId(productId);
            //赋值用户id
            productInfo.setUserId(userInfo.getId().toString());
            //产品类型
            productInfo.setProductType(0);
            //为新产品赋值订单模板编号
            productInfo.setOrderSn(productInfo.getOrderSn());
            productInfo.setTemplateSn(productInfo.getTemplateSn());
            //创建产品
            int code = logicService.insert_products(productInfo);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "创建新产品成功");
                obj.put("productId", productId);
                obj.put("orderSn", productInfo.getOrderSn());
                obj.put("templateSn", productInfo.getTemplateSn());
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "创建新产品失败");
                obj.put("productId", "0");
                obj.put("orderSn", "0");
                obj.put("templateSn", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "创建产品失败，请重新创建");
            return obj;
        }
    }

    /**
     * 根据产品id修改产品信息
     * @return
     */
    @PostMapping(value = "/update_products")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_update_products(ProductInfo productInfo){
        JSONObject obj = new JSONObject();//返回对象
//        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(productInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            if(productInfo.getId()==null || "".equals(productInfo.getId())){
                obj.put("code", 5);
                obj.put("msg", "产品id为空，保存或更新失败");
                return obj;
            }
            if(productInfo.getOrderSn()==null || "".equals(productInfo.getOrderSn())){
                obj.put("code", 6);
                obj.put("msg", "订单编号为空，保存或更新失败");
                return obj;
            }
            String sex_id = "";
            String gongyi_id="";
            String plateId = "";//声明版号id
            String pingle_id = "";//声明品类id
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            double lost_price1=0,lost_price2=0;//最终价格
            //拿到类别id
            if(productInfo.getCategoryIds()!=null && !"".equals(productInfo.getCategoryIds())){
                String pinglei[] = productInfo.getCategoryIds().split(",");
                List<String> resultList= new ArrayList<>(Arrays.asList(pinglei));
                double cost = 0,zhe_price=0;
                String categoryImg = "";
                if(resultList.size()>=1 && resultList.size()<2){
                    //拿到类别名称和价格
                    CategoryInfo categoryInfodetail = logicService.query_categoryDetailInfo(resultList.get(0));
                    if(categoryInfodetail!=null){
                        categoryImg = categoryInfodetail.getImg();
                        if("女装".equals(categoryInfodetail.getCategoryName())){
                            productInfo.setSex(1);
                            sex_id=CommonConstant.category_sex_nv;
                        }else {
                            productInfo.setSex(0);
                            sex_id=CommonConstant.category_sex_nan;
                        }
                    }
                }else if(resultList.size()>=2){
                    //拿到类别名称和价格
                    CategoryInfo categoryInfodetail2 = logicService.query_categoryDetailInfo(resultList.get(0));
                    CategoryInfo categoryInfodetail = logicService.query_categoryDetailInfo(resultList.get(1));
                    if(categoryInfodetail!=null){
                        categoryImg = categoryInfodetail.getImg();
                    }
                    if("女装".equals(categoryInfodetail2.getCategoryName())){
                        productInfo.setSex(1);
                        sex_id=CommonConstant.category_sex_nv;
                    }else {
                        productInfo.setSex(0);
                        sex_id=CommonConstant.category_sex_nan;
                    }
                    productInfo.setProductName(categoryInfodetail.getCategoryName()+"-"+categoryInfodetail.getCategoryCode());
                }
                for (String s:pinglei){
                    //拿到类别名称和价格
                    CategoryInfo categoryInfodetail = logicService.query_categoryDetailInfo(s);
                    if(categoryInfodetail!=null){
                        if(categoryInfodetail.getIsType()==3){
                            plateId = categoryInfodetail.getId().toString();//拿到版号
                        }
                        if(categoryInfodetail.getIsType()==2){
                            pingle_id = categoryInfodetail.getId().toString();//拿到品类id
                        }
                        if(categoryInfodetail.getIsType()==4){
                            gongyi_id = categoryInfodetail.getId().toString();//拿到工艺id
                        }
                        /**默认0：表示订单里面的款式工艺，2表示品类，3版号,4工艺*/
                        if(categoryInfodetail.getIsType()==4){
                            String category_code = categoryInfodetail.getCategoryCode();//拿到工艺的编号
                            //根据编号和上级品类id查询
                            CategoryInfo categoryInfodetail2 = logicService.query_categoryDetailBytop_id(pingle_id,category_code);
                           //拿到工艺id查询价格体系表
                            PriceSystemPinleiInfo priceSystemPinleiInfo = logicService.query_pricesysytemDetail(categoryInfodetail2.getId().toString(),"0","1");
                            if(priceSystemPinleiInfo!=null){
                                //拿到价格体系id
                                String price_systemId = priceSystemPinleiInfo.getId().toString();
                                //拿到体系主键id查询价格区间
                                List<PriceSystemQujianInfo> qujian_pricelist = logicService.query_pricequjian(price_systemId);
                                if(qujian_pricelist.size()>0){
                                    for(int i=0;i<qujian_pricelist.size();i++){
                                       if(qujian_pricelist.get(i).getMinNumbers()<=1 && qujian_pricelist.get(i).getMaxNumbers()>=1){
                                           lost_price1+=Double.parseDouble(qujian_pricelist.get(i).getPrice());//产品售价
                                       }
                                    }
                                }else {
                                    System.out.println("没有没有适合的价格区间=");
                                }
                            }else {
                                System.out.println("没有设置价格体系="+categoryInfodetail.getIsType());
                            }
                        }else {
//                            System.out.println("是公益吗="+categoryInfodetail.getIsType());
                        }
                    }
                }
               productInfo.setProductImg(categoryImg);
                //根据版号id查询所欲的参数
                String relae_ids = "";
                List<CategoryInfo> categoryInfoList = logicService.query_categorylistByplateId(plateId);
                if(categoryInfoList.size()>0){
                    for (String s:pinglei){
                        for (int i=0;i<categoryInfoList.size();i++){
                            if(categoryInfoList.get(i).getId().toString().equals(s)){
                                relae_ids+=",";
                                relae_ids+=categoryInfoList.get(i).getId().toString();
                            }
                        }
                    }
                }
                productInfo.setCategoryIds(sex_id+","+pingle_id+","+plateId+","+gongyi_id+relae_ids);
            }
            //判断是否拿到里布、底领尼、纽扣
            String libu_id = productInfo.getLibuId();
            String dingli_id = productInfo.getDilinliId();
            String niukou_id = productInfo.getButtonsIds();
            CategoryMaterialInfo categoryMaterialInfo = logicService.query_materialDetail(libu_id,plateId,1);
            if(categoryMaterialInfo!=null){
                productInfo.setLibuId(categoryMaterialInfo.getOtherId());
            }else {
                productInfo.setLibuId("");
            }
            CategoryMaterialInfo categoryMaterialInfo2 = logicService.query_materialDetail(dingli_id,plateId,2);
            if(categoryMaterialInfo2!=null){
                productInfo.setDilinliId(categoryMaterialInfo2.getOtherId());
            }else {
                productInfo.setDilinliId("");
            }
            CategoryMaterialInfo categoryMaterialInfo3 = logicService.query_materialDetail(niukou_id,plateId,3);
            if(categoryMaterialInfo3!=null){
                productInfo.setButtonsIds(categoryMaterialInfo3.getOtherId());
            }else {
                productInfo.setButtonsIds("");
            }
            //判断绣字类型
            String xiuzi_ziti="",xiuzi_img="",xiuzi_one="",xiuzi_two="",xiuzi_color="",zidingyi_img="";
            String height = productInfo.getXiuziHeight();
            String buwei = productInfo.getXiuziWeizhi();
            String xiuzi_type = productInfo.getXiuziType()+"";
            if(xiuzi_type.equals("自定义图片")){
                zidingyi_img = productInfo.getZidingyiImg();
            }else if(xiuzi_type.equals("文字")){
                xiuzi_ziti= productInfo.getXiuziZiti();
                xiuzi_one = productInfo.getXiuziOneNeirong();
                xiuzi_two = productInfo.getXiuziTwoNeirong();
                xiuzi_color = productInfo.getXiuziColor();
            }else if(xiuzi_type.equals("图片")){
                xiuzi_img= productInfo.getXiuziImg();
                xiuzi_color = productInfo.getXiuziColor();
            }else{
                height="";
                buwei = "";
                xiuzi_type = "无绣字";
            }
            productInfo.setXiuziType(xiuzi_type);
            productInfo.setXiuziZiti(xiuzi_ziti);
            productInfo.setXiuziImg(xiuzi_img);
            productInfo.setXiuziColor(xiuzi_color);
            productInfo.setXiuziOneNeirong(xiuzi_one);
            productInfo.setXiuziTwoNeirong(xiuzi_two);
            productInfo.setZidingyiImg(zidingyi_img);
            productInfo.setXiuziHeight(height);
            productInfo.setXiuziWeizhi(buwei);

            String zhuangses="";
            //拿到撞色
            if(productInfo.getZhuangseIds()!=null && !"".equals(productInfo.getZhuangseIds())){
                //根据品类有哪些撞色
                List<ContrastcolorInfo> contrastcolorInfoList = logicService.query_AllContrastInfoByCategoryId(plateId);
                if(contrastcolorInfoList.size()>0){
                    String zhuangse_id[] = productInfo.getZhuangseIds().split(",");
                    for (String s:zhuangse_id){
                        String size2[] = s.split("/");
                        if(size2==null || "".equals(size2[0]) || "".equals(size2[1])){
                            continue;
                        }
                       for (int i=0;i<contrastcolorInfoList.size();i++){
                           if(contrastcolorInfoList.get(i).getId().toString().equals(size2[0])){
                               if (!"".equals(zhuangses)) {
                                   zhuangses+=",";
                               }
                               zhuangses+=contrastcolorInfoList.get(i).getId()+"/"+size2[1];
                           }
                       }
                    }
                }
            }
            productInfo.setZhuangseIds(zhuangses);

//            //计算纽扣的价格
//            if(productInfo.getButtonsIds()!=null && !"".equals(productInfo.getButtonsIds())){
//                String buttons[] = productInfo.getButtonsIds().split(",");
//                for (String s:buttons){
//                    ButtonsInfo buttonsInfo = logicService.query_buttonsInfo(s);
//                    if(buttonsInfo!=null){
//                        lost_price1+=Double.parseDouble(buttonsInfo.getRetailPrice());
//                    }
//                }
//            }
//            //计算里布的价格
//            if(productInfo.getLibuId()!=null && !"".equals(productInfo.getLibuId())){
//                CategoryMaterialInfo materialinfo = logicService.query_materialInfo(productInfo.getLibuId(),0);
//                if(materialinfo!=null){
//                    lost_price1+=Double.parseDouble(materialinfo.getSalesPrice());
//                }
//            }
//            //计算底领尼的价格
//            if(productInfo.getDilinliId()!=null && !"".equals(productInfo.getDilinliId())){
//                CategoryMaterialInfo materialinfo = logicService.query_materialInfo(productInfo.getLibuId(),1);
//                if(materialinfo!=null){
//                    lost_price1+=Double.parseDouble(materialinfo.getSalesPrice());
//                }
//            }
            //格式化类
            String zheqian = new DecimalFormat("0.00").format(lost_price1);
            String zhehou = new DecimalFormat("0.00").format(lost_price2);
            productInfo.setZheqianPrice(Double.parseDouble(zheqian));
            productInfo.setZhehouPrice(Double.parseDouble(zhehou));

            String webbodysize="";
            String nobodysize = "";
            if(productInfo.getBodySizeIds()!=null && !"".equals(productInfo.getBodySizeIds())){
                //获取前端传过来的尺寸ids
//                String oldbody_sizes = productInfo.getBodySizeIds();
                List<BodySizeInfo> bodySizeInfoList = logicService.query_bodySizeinfoByplateId(plateId);
                //拿到前端传入的尺寸值
                String bodysize1[] = productInfo.getBodySizeIds().split(",");
                for (String s:bodysize1){
                    String size2[] = s.split("/");
//                    System.out.println(s+"=进来ad=="+size2[0]+"=="+size2[1]);
                    if(size2==null || "".equals(size2[0]) || "".equals(size2[1])){
                        continue;
                    }
                    for (int i=0;i<bodySizeInfoList.size();i++){
//                        System.out.println(bodySizeInfoList.get(i).getId()+"==2222222=="+size2[0]);
                        if(bodySizeInfoList.get(i).getId().toString().equals(size2[0])){
                            if (!"".equals(webbodysize)) {
                                webbodysize+=",";
                                nobodysize+=",";
                            }
                            nobodysize+=bodySizeInfoList.get(i).getId();
                            webbodysize+=bodySizeInfoList.get(i).getId()+"/"+size2[1];
                        }
                    }
                }
//                String bodysizes = strbody.substring(0,strbody.length()-1);
                productInfo.setBodySizeIds(nobodysize);
                productInfo.setOldbodySizeIds(webbodysize);//变化之前的
                //拿到前端传入的尺寸值尚未变化之前的
                logicService.delete_product_bodysize(productInfo.getId());
                if(webbodysize!=null && !"".equals(webbodysize)){
                    String size1[] = webbodysize.split(",");
                    if(size1!=null && size1.length>0){
                        for (String s:size1){
                            String size2[] = s.split("/");
                            logicService.add_Order_sizeInfo(productInfo.getId(),size2[0],size2[1],"0",new Date());
                        }
                    }
                }
            }
            //更新产品
            int code = logicService.update_products(productInfo);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "更新产品成功2!");
                obj.put("orderSn", productInfo.getOrderSn());
                obj.put("templateSn", productInfo.getTemplateSn());
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "更新产品失败");
                obj.put("orderSn", productInfo.getOrderSn());
                obj.put("templateSn", productInfo.getTemplateSn());
                return obj;
            }
//        } catch (Exception e) {
//            obj.put("code", 2);
//            obj.put("msg", "更新产品失败，请重新创建");
//            return obj;
//        }
    }

    /**
     * 根据订单号查询产品
     * @return
     */
    @PostMapping(value = "/query_AllproductsByordersn")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_query_AllproductsByordersn(ProductInfo productInfo) {
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(productInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            //根据订单号查询产品
            List<ProductInfo> datalist = logicService.query_productInfoByorderSn(userInfo.getId().toString(),productInfo.getOrderSn());
            if(datalist.size()>0){
                for (int i = 0;i<datalist.size();i++){
                    //拿到类别id
                    if(datalist.get(i).getCategoryIds()!=null && !"".equals(datalist.get(i).getCategoryIds())){
                        String pinglei[] = datalist.get(i).getCategoryIds().split(",");
                        List<String> resultList= new ArrayList<>(Arrays.asList(pinglei));
                       if(resultList.size()>=2){
                            //拿到类别名称和价格
                            CategoryInfo categoryInfodetail = logicService.query_categoryDetailInfo(resultList.get(1));
                            if(categoryInfodetail!=null){
                                datalist.get(i).setLeibieName(categoryInfodetail.getCategoryName());
                            }else {
                                datalist.get(i).setLeibieName("暂无");
                            }
                        }else {
                           datalist.get(i).setLeibieName("暂无");
                       }
                    }else {
                        datalist.get(i).setLeibieName("暂无");
                    }
                    //拿到面料id
                    if(datalist.get(i).getFabricIds()!=null && !"".equals(datalist.get(i).getFabricIds())){
                        String pinglei[] = datalist.get(i).getFabricIds().split(",");
                        for (String s:pinglei){
                            //拿到类别名称和价格
                            String size2[] = s.split("/");
                            System.out.print("chuai222==="+size2[0]);
                            FabricInfo fabricInfodetail = logicService.query_fabricDetailInfo(size2[0]);
                            if(fabricInfodetail!=null){
                                datalist.get(i).setFabricName(fabricInfodetail.getFabricCode());
                            }else {
                                datalist.get(i).setFabricName("暂无");
                            }
                        }
                    }else {
                        datalist.get(i).setFabricName("暂无");
                    }
                }
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", datalist);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "查询失败");
                obj.put("data", datalist);
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "参数错误");
            return obj;
        }
    }

    /**
     * 使用模板-创建订单
     * @return
     */
    @PostMapping(value = "/useTemplate_createOrder")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_useTemplate_createOrder(SingleOrderInfo orderInfo) {
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(orderInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            //获取汉子的首字母
            WordUtils word = new WordUtils();
            String zimuname = word.getUpperCase(userInfo.getRealname(),false);
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(100000)+1;//为变量赋随机值1-99999999;
            String order_sn = "S"+zimuname+(startTs.toString())+random;
            orderInfo.setOrderSn(order_sn);
            orderInfo.setUserId(userInfo.getId().toString());
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(orderInfo.getOrderName()==null || "".equals(orderInfo.getOrderName())){
                orderInfo.setOrderName(f.format(new Date())+"订单");
            }
            //模板编号
            Long startTs_mb = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random_mb=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            String newtemplateSn = "NEWSINGMB"+startTs_mb+random_mb;

            String oldproductid ="";
            //根据模板编号查询模板信息
            TemplateRecordInfo templateInfo = logicService.query_templateRecordInfo(orderInfo.getTemplateSn());
            if(templateInfo!=null){
                orderInfo.setOrderName(templateInfo.getTemplateName());//订单名字
                orderInfo.setStoreId(" ");//门店id
                orderInfo.setStoreCode(" ");//门店编码
                orderInfo.setCustomerCode(" ");//客户编码
                orderInfo.setCustomerName(" ");//客户名称
                orderInfo.setCustomerSex("0");//客户性别
                orderInfo.setFabricSource(templateInfo.getMianliaoSource());//面料来源
                orderInfo.setBusinessSource(templateInfo.getYewuType());//业务来源
                orderInfo.setPackageType(templateInfo.getPackageType());//包装方式
                orderInfo.setCourierId(templateInfo.getKuaidiId());//快递id
                orderInfo.setAddressType(templateInfo.getAddressType());//地址类型
                orderInfo.setAddress(" ");//地址
                orderInfo.setThirdSn(templateInfo.getThirdSn());//第三方运单号
                orderInfo.setStatus(0);
                orderInfo.setSysOrgCode(userInfo.getOrgCode());
                //模板里面的产品ids
                if(templateInfo.getChanpinIds()!=null && !"".equals(templateInfo.getChanpinIds())){
                    String chanpinids[] = templateInfo.getChanpinIds().split(",");
                    String productids ="";
                    for (String s:chanpinids){
                        ProductInfo productInfo1 = logicService.query_productDetail(s);
                        //产品表
                        SimpleDateFormat f2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        if(productInfo1.getProductName()==null || "".equals(productInfo1.getProductName())){
                            productInfo1.setProductName(f2.format(new Date())+"产品");
                        }
                        //获取汉子的首字母
                        WordUtils word2 = new WordUtils();
                        String zimuname2 = word2.getUpperCase(userInfo.getRealname(),false);
                        Long startTs2 = System.currentTimeMillis(); // 当前时间戳
                        //8位随机数
                        int random2=new Random().nextInt(10000000)+1;//为变量赋随机值1-99999999;
                        String productSn = zimuname2+(startTs2.toString());
                        String productId = startTs.toString()+random2;
                        System.out.print("产品主键==="+productId+"==="+random2);
                        //赋值产品货号
                        productInfo1.setProductCode(productSn);
                        //赋值产品id
                        productInfo1.setId(productId);
                        //赋值用户id
                        productInfo1.setUserId(userInfo.getId().toString());
                        //产品类型
                        productInfo1.setProductType(0);
                        productInfo1.setOrderSn(order_sn);//订单编号
                        productInfo1.setTemplateSn(newtemplateSn);//新的模板编号
                        if(productInfo1.getOldbodySizeIds()!=null){
                            //拿到前端传入的尺寸值尚未变化之前的
                            String size1[] = productInfo1.getOldbodySizeIds().split(",");
                            for (String s2:size1){
                                String size2[] = s2.split("/");
                                logicService.add_Order_sizeInfo(productId,size2[0],size2[1],"0",new Date());
                            }
                        }
                        //创建新产品
                        int code = logicService.insert_products(productInfo1);
                        if(code>0){
                            productids+=productId+",";
                            System.out.print("产品创建成功");
                        }else {
                            System.out.print("产品创建失败");
                        }
                    }
                    oldproductid = productids.substring(0,productids.length()-1);
                    orderInfo.setChanpingIds(oldproductid);
                    templateInfo.setChanpinIds(oldproductid);
                    System.out.print("产品主键22==="+oldproductid+"==="+productids);
                }
            }
            String chanpinids2[] = oldproductid.split(",");
            //赋值模板编号
            templateInfo.setOrderSn(newtemplateSn);
            templateInfo.setUserId(userInfo.getId().toString());
            templateInfo.setCompanyCode(userInfo.getCompanyOrgcode());
            templateInfo.setSysOrgCode(userInfo.getOrgCode());
            templateInfo.setStatus(1);
            //创建个订新订单
            int code = logicService.add_signOrderInfo(orderInfo);
            //创建个订新模板
            int code2 = logicService.add_templateInfo(templateInfo);
            if(code>0 && code2>0){
                obj.put("code", 0);
                obj.put("msg", "使用模板创建订单成功");
                obj.put("productId", chanpinids2[0]);
                obj.put("order_sn", order_sn);
                obj.put("templateSn", newtemplateSn);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "使用模板创建订单失败");
                obj.put("productId","0");
                obj.put("order_sn", "0");
                obj.put("templateSn", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "订单失败，请重新创建");
            obj.put("order_sn", "0");
            return obj;
        }
    }

    /**
     * 创建空白团订订单
     * @return
     */
    @PostMapping(value = "/create_team_order")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_create_team_order(TeamOrderInfo teamOrderInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(teamOrderInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(teamOrderInfo.getOrderName()==null || "".equals(teamOrderInfo.getOrderName())){
                teamOrderInfo.setOrderName(f.format(new Date())+"team订单");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            String order_sn = "TEAM"+startTs.toString()+random;
            teamOrderInfo.setOrderSn(order_sn);
            teamOrderInfo.setUserId(userInfo.getId().toString());
            teamOrderInfo.setSysOrgCode(userInfo.getOrgCode());
            System.out.print("产品主键==="+order_sn+"==="+random);
            //创建团订订单
            int code = logicService.insert_team_order(teamOrderInfo);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "创建团订订单成功");
                obj.put("orderSn", order_sn);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "创建团订订单失败");
                obj.put("orderSn", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "创建团订订单失败，请重新创建");
            return obj;
        }
    }

    /**
     * 更新团订订单
     * @return
     */
    @PostMapping(value = "/update_team_order")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_update_team_order(TeamOrderInfo teamOrderInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(teamOrderInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            System.out.println("status==="+teamOrderInfo.getStatus());
            if(teamOrderInfo.getIs_ding()==0){
                TeamOrderInfo teaminfo = logicService.queryOrderDetail(teamOrderInfo.getOrderSn());
                System.out.println("家里看了看==="+teamOrderInfo.getIs_ding()+"==="+teaminfo.getStatus());
                if(teaminfo!=null){
                    if(teaminfo.getStatus()==11){
                        teamOrderInfo.setStatus(11);
                    }else {
                        teamOrderInfo.setStatus(0);
                    }
                }
            }
            //更新团订订单
            int code = logicService.update_team_order(teamOrderInfo);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "更新团订订单成功");
                obj.put("orderSn", teamOrderInfo.getOrderSn());
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "更新团订订单失败");
                obj.put("orderSn", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "更新团订订单失败，请重新创建");
            return obj;
        }
    }

    /**
     * 保存团订模板
     * @return
     */
    @PostMapping(value = "/create_team_templateInfo")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_create_team_templateInfo(TeamTemplateInfo templateInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(templateInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(templateInfo.getOrderName()==null || "".equals(templateInfo.getOrderName())){
                templateInfo.setOrderName(f.format(new Date())+"team订单");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            String order_sn = "MBTM"+startTs.toString()+random;
            templateInfo.setOrderSn(order_sn);
            templateInfo.setUserId(userInfo.getId().toString());
            templateInfo.setCompanyCode(userInfo.getCompanyOrgcode());
            templateInfo.setSysOrgCode(userInfo.getOrgCode());
            //创建团订模板
            int code = logicService.insert_team_template(templateInfo);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "创建团订模板成功");
                obj.put("orderSn", order_sn);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "创建团订模板失败");
                obj.put("orderSn", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "创建团订模板失败，请重新创建");
            return obj;
        }
    }

    /**
     * 更新团订模板--设置排序
     * @return
     */
    @PostMapping(value = "/update_team_templateInfo")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_update_team_templateInfo(TeamTemplateInfo templateInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(templateInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            //创建团订模板
            int code = logicService.update_team_template(templateInfo);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "设置成功");
                obj.put("orderSn", templateInfo.getOrderSn());
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "设置失败");
                obj.put("orderSn", "0");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "设置失败，参数错误");
            return obj;
        }
    }


    /**
     * 根据用户id和type查询团订中的编辑中的订单或者模板
     * @return
     */
    @PostMapping(value = "/query_TeamOrderlistBytype")
    public JSONObject post_query_TeamOrderlistBytype(@RequestParam(name="token") String token,
                                               @RequestParam(name="type") int type,
                                               @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                               @RequestParam(name="pageNo", defaultValue="1") Integer pageNo) {
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        //type:1查询订单，2查询我的模板，3查询明朗云模板
        Page<TeamTemplateInfo> page = new Page<TeamTemplateInfo>(pageNo, pageSize);
        if(type==1){
            IPage<TeamTemplateInfo> pageList = logicService.query_teamTemplateInfo(page,userInfo.getId().toString(),userInfo.getCompanyOrgcode(),type);
            if(pageList != null){
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", pageList);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "暂无数据");
                obj.put("data", pageList);
                return obj;
            }
        }else {
            IPage<TeamTemplateInfo> pageList = logicService.query_teamTemplateInfo(page,userInfo.getId().toString(),userInfo.getCompanyOrgcode(),type);
            if(pageList != null){
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", pageList);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "暂无数据");
                obj.put("data", pageList);
                return obj;
            }
        }
    }

    /**
     * 使用团订模板--创建团订订单
     * @return
     */
    @PostMapping(value = "/use_teamTemplateInfo_CreatOrder")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_use_teamTemplateInfo_CreatOrder(TeamTemplateInfo templateInfo){
        JSONObject obj = new JSONObject();//返回对象
//        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(templateInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            TeamOrderInfo teamOrderInfo = new TeamOrderInfo();
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if(teamOrderInfo.getOrderName()==null || "".equals(teamOrderInfo.getOrderName())){
                teamOrderInfo.setOrderName(f.format(new Date())+"team订单");
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            String order_sn = "TEAM"+startTs.toString()+random;
            teamOrderInfo.setOrderSn(order_sn);//设置订单编号
            teamOrderInfo.setUserId(userInfo.getId().toString());//设置用户id
            teamOrderInfo.setSysOrgCode(userInfo.getOrgCode());
            //根据模板编号查询模板详情
            TeamTemplateInfo mbdetail = logicService.query_teamTemplateDetailInfo(templateInfo.getOrderSn());
            if(mbdetail!=null){
                teamOrderInfo.setOrderName(mbdetail.getOrderName());//设置订单名称
                teamOrderInfo.setStoreId(mbdetail.getStoreId());
                teamOrderInfo.setStoreCode(mbdetail.getStoreCode());
                teamOrderInfo.setFabricSource(mbdetail.getFabricSource());
                teamOrderInfo.setBusinessSource(mbdetail.getBusinessSource());
                teamOrderInfo.setCourierId(mbdetail.getCourierId());
                teamOrderInfo.setPackageType(mbdetail.getPackageType());
                teamOrderInfo.setAddressType(mbdetail.getAddressType());
                teamOrderInfo.setAddress(mbdetail.getAddress());
                teamOrderInfo.setRemark(mbdetail.getRemark());//订单备注
                //声明客户编码
                String customer_code = "CUSTOMER"+startTs.toString()+random;
                //根据用户id查询客户信息再创建客户
                CustomerInfo customerInfo1 =logicService.query_customerDetailByid(mbdetail.getCustomerId(),1);
                if(customerInfo1!=null){
                    CustomerInfo customerInfo2 = new CustomerInfo();
                    customerInfo2.setCustomerCode(customer_code);
                    customerInfo2.setCustomerName(customerInfo1.getCustomerName());
                    customerInfo2.setSex(customerInfo1.getSex());
                    customerInfo2.setReferred(customerInfo1.getReferred());
                    customerInfo2.setIsCompany(1);
                    customerInfo2.setPhone(customerInfo1.getPhone());
                    customerInfo2.setAddress(customerInfo1.getAddress());
                    customerInfo2.setRemark(customerInfo1.getRemark());
                    int code1 = logicService.add_newcustomer(customerInfo2);
                    if(code1>0){
                        System.out.println("添加客户==="+code1);
                        //添加客户成功
                        CustomerInfo customerDetail = logicService.query_customerDetailByid(customer_code,2);
                        if(customerDetail!=null){
                            System.out.println("添加客户成功==="+customerDetail.getId().toString());
                            teamOrderInfo.setCustomerId(customerDetail.getId().toString());//赋值客户id
                            //执行根据客户id查询客户下的所有部门
                            List<CustomerDepartInfo> kehu_departlist = logicService.query_cusdepartList(mbdetail.getCustomerId());
                            if(kehu_departlist.size()>0){
                                for (int i=0;i<kehu_departlist.size();i++){
                                    String depart_code = "DEPART"+startTs.toString()+random+i;
                                    CustomerDepartInfo kehudepart = new CustomerDepartInfo();
                                    kehudepart.setDepartName(kehu_departlist.get(i).getDepartName());
                                    kehudepart.setCode(depart_code);
                                    kehudepart.setCustomerId(customerDetail.getId().toString());
                                    kehudepart.setConsignee(kehu_departlist.get(i).getConsignee());
                                    kehudepart.setAddress(kehu_departlist.get(i).getAddress());
                                    kehudepart.setPhone(kehu_departlist.get(i).getPhone());
                                    kehudepart.setRemark(kehu_departlist.get(i).getRemark());
                                    int code2 = logicService.add_newcustomer_depart(kehudepart);
                                    System.out.println("添加22==="+kehu_departlist.get(i).getDepartName());
                                    if(code2>0){
                                        //执行根据客户id查询客户下的所有部门
                                        List<ProductInfo> depart_productlist = logicService.query_productBydepartId(kehu_departlist.get(i).getId());
                                        if(depart_productlist.size()>0){
                                            //根据编码拿到部门id
                                            CustomerDepartInfo departDetail = logicService.query_CustomerDepartDetailByid(depart_code,2);
                                            if(departDetail!=null){
                                                for (int k=0;k<depart_productlist.size();k++){
                                                    System.out.println(depart_productlist.get(k).getXiuziType()+"=绣字字体==");
                                                    String product_id = "PRODUCTID"+startTs.toString()+random+k;
                                                    String product_hao = "PRODUCTCODE"+startTs.toString()+random+k;
                                                    ProductInfo productInfo = new ProductInfo();
                                                    productInfo.setId(product_id);
                                                    productInfo.setProductCode(product_hao);
                                                    productInfo.setProductName(depart_productlist.get(k).getProductName());
                                                    productInfo.setProductImg(depart_productlist.get(k).getProductImg());
                                                    productInfo.setSex(depart_productlist.get(k).getSex());
                                                    productInfo.setProductType(depart_productlist.get(k).getProductType());
                                                    productInfo.setZheqianPrice(0.00);
                                                    productInfo.setZhehouPrice(0.00);
                                                    productInfo.setCategoryIds(depart_productlist.get(k).getCategoryIds());
                                                    productInfo.setFabricIds(depart_productlist.get(k).getFabricIds());
                                                    productInfo.setStatus(0);
                                                    productInfo.setRemark(depart_productlist.get(k).getRemark());
                                                    productInfo.setXiuziType(depart_productlist.get(k).getXiuziType());
                                                    productInfo.setXiuziWeizhi(depart_productlist.get(k).getXiuziWeizhi());
                                                    productInfo.setXiuziImg(depart_productlist.get(k).getXiuziImg());
                                                    productInfo.setXiuziColor(depart_productlist.get(k).getXiuziColor());
                                                    productInfo.setXiuziHeight(depart_productlist.get(k).getXiuziHeight());
                                                    productInfo.setXiuziZiti(depart_productlist.get(k).getXiuziZiti());
                                                    productInfo.setZidingyiImg(depart_productlist.get(k).getZidingyiImg());
                                                    productInfo.setZhuangseIds(depart_productlist.get(k).getZhuangseIds());
                                                    productInfo.setXiuziOneNeirong(depart_productlist.get(k).getXiuziOneNeirong());
                                                    productInfo.setXiuziTwoNeirong(depart_productlist.get(k).getXiuziTwoNeirong());
                                                    productInfo.setLibuId(depart_productlist.get(k).getLibuId());
                                                    productInfo.setDilinliId(depart_productlist.get(k).getDilinliId());
                                                    productInfo.setButtonsIds(depart_productlist.get(k).getButtonsIds());
                                                    productInfo.setXiuziPriceId(depart_productlist.get(k).getXiuziPriceId());
                                                    productInfo.setBodySizeIds(depart_productlist.get(k).getBodySizeIds());
                                                    productInfo.setOldbodySizeIds(depart_productlist.get(k).getOldbodySizeIds());
                                                    productInfo.setSizeIds(depart_productlist.get(k).getSizeIds());
                                                    int code3 = logicService.insert_products(productInfo);
                                                    if(code3>0){
                                                        System.out.println("添加产品33==="+product_id);
                                                        //执行添加产品到部门
                                                        logicService.add_newdepart_product(product_id,departDetail.getId(),"使用模板创建的产品");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //创建团订订单
            int code = logicService.insert_team_order(teamOrderInfo);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "使用模板创建订单成功");
                obj.put("orderSn", order_sn);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "创建团订订单失败");
                obj.put("orderSn", "0");
                return obj;
            }
//        } catch (Exception e) {
//            obj.put("code", 2);
//            obj.put("msg", "设置失败，参数错误");
//            return obj;
//        }
    }


    /**
     * 复制团订订单
     * @return
     */
    @PostMapping(value = "/copy_team_order")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_copy_team_order(TeamOrderInfo templateInfo){
        JSONObject obj = new JSONObject();//返回对象
//        try {
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(templateInfo.getToken(), 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        TeamOrderInfo teamOrderInfo = new TeamOrderInfo();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(teamOrderInfo.getOrderName()==null || "".equals(teamOrderInfo.getOrderName())){
            teamOrderInfo.setOrderName(f.format(new Date())+"team订单");
        }
        Long startTs = System.currentTimeMillis(); // 当前时间戳
        //8位随机数
        int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
        String order_sn = "TEAM"+startTs.toString()+random;
        teamOrderInfo.setOrderSn(order_sn);//设置订单编号
        teamOrderInfo.setUserId(userInfo.getId().toString());//设置用户id
        teamOrderInfo.setSysOrgCode(userInfo.getOrgCode());
        //根据订单编号查询订单详情
        TeamOrderInfo mbdetail = logicService.queryOrderDetail(templateInfo.getOrderSn());
        if(mbdetail!=null){
            teamOrderInfo.setOrderName(mbdetail.getOrderName());//设置订单名称
            teamOrderInfo.setStoreId(mbdetail.getStoreId());
            teamOrderInfo.setStoreCode(mbdetail.getStoreCode());
            teamOrderInfo.setFabricSource(mbdetail.getFabricSource());
            teamOrderInfo.setBusinessSource(mbdetail.getBusinessSource());
            teamOrderInfo.setCourierId(mbdetail.getCourierId());
            teamOrderInfo.setPackageType(mbdetail.getPackageType());
            teamOrderInfo.setAddressType(mbdetail.getAddressType());
            teamOrderInfo.setAddress(mbdetail.getAddress());
            teamOrderInfo.setRemark(mbdetail.getRemark());//订单备注
            teamOrderInfo.setStatus(0);
            //声明客户编码
            String customer_code = "CUSTOMER"+startTs.toString()+random;
            //根据用户id查询客户信息再创建客户
            CustomerInfo customerInfo1 =logicService.query_customerDetailByid(mbdetail.getCustomerId(),1);
            if(customerInfo1!=null){
                CustomerInfo customerInfo2 = new CustomerInfo();
                customerInfo2.setCustomerCode(customer_code);
                customerInfo2.setCustomerName(customerInfo1.getCustomerName());
                customerInfo2.setSex(customerInfo1.getSex());
                customerInfo2.setReferred(customerInfo1.getReferred());
                customerInfo2.setIsCompany(1);
                customerInfo2.setPhone(customerInfo1.getPhone());
                customerInfo2.setAddress(customerInfo1.getAddress());
                customerInfo2.setRemark(customerInfo1.getRemark());
                int code1 = logicService.add_newcustomer(customerInfo2);
                if(code1>0){
                    //添加客户成功
                    CustomerInfo customerDetail = logicService.query_customerDetailByid(customer_code,2);
                    if(customerDetail!=null){
                        teamOrderInfo.setCustomerId(customerDetail.getId().toString());//赋值客户id
                        //执行根据客户id查询客户下的所有部门
                        List<CustomerDepartInfo> kehu_departlist = logicService.query_cusdepartList(mbdetail.getCustomerId());
                        if(kehu_departlist.size()>0){
                            for (int i=0;i<kehu_departlist.size();i++){
                                String depart_code = "DEPART"+startTs.toString()+random+i;
                                CustomerDepartInfo kehudepart = new CustomerDepartInfo();
                                kehudepart.setDepartName(kehu_departlist.get(i).getDepartName());
                                kehudepart.setCode(depart_code);
                                kehudepart.setCustomerId(customerDetail.getId().toString());
                                kehudepart.setConsignee(kehu_departlist.get(i).getConsignee());
                                kehudepart.setAddress(kehu_departlist.get(i).getAddress());
                                kehudepart.setPhone(kehu_departlist.get(i).getPhone());
                                kehudepart.setRemark(kehu_departlist.get(i).getRemark());
                                int code2 = logicService.add_newcustomer_depart(kehudepart);
                                if(code2>0){
                                    //执行根据客户id查询客户下的所有部门
                                    List<ProductInfo> depart_productlist = logicService.query_productBydepartId(kehu_departlist.get(i).getId());
                                    if(depart_productlist.size()>0){
                                        //根据编码拿到部门id
                                        CustomerDepartInfo departDetail = logicService.query_CustomerDepartDetailByid(depart_code,2);
                                        if(departDetail!=null){
                                            for (int k=0;k<depart_productlist.size();k++){
                                                String product_id = "PRODUCTID"+startTs.toString()+random+k;
                                                String product_hao = "PRODUCTCODE"+startTs.toString()+random+k;
                                                ProductInfo productInfo = new ProductInfo();
                                                productInfo.setId(product_id);
                                                productInfo.setProductCode(product_hao);
                                                productInfo.setProductName(depart_productlist.get(k).getProductName());
                                                productInfo.setProductImg(depart_productlist.get(k).getProductImg());
                                                productInfo.setSex(depart_productlist.get(k).getSex());
                                                productInfo.setProductType(depart_productlist.get(k).getProductType());
                                                productInfo.setZheqianPrice(0.00);
                                                productInfo.setZhehouPrice(0.00);
                                                productInfo.setCategoryIds(depart_productlist.get(k).getCategoryIds());
                                                productInfo.setFabricIds(depart_productlist.get(k).getFabricIds());
                                                productInfo.setStatus(0);
                                                productInfo.setRemark(depart_productlist.get(k).getRemark());
                                                productInfo.setXiuziType(depart_productlist.get(k).getXiuziType());
                                                productInfo.setXiuziWeizhi(depart_productlist.get(k).getXiuziWeizhi());
                                                productInfo.setXiuziImg(depart_productlist.get(k).getXiuziImg());
                                                productInfo.setXiuziColor(depart_productlist.get(k).getXiuziColor());
                                                productInfo.setXiuziHeight(depart_productlist.get(k).getXiuziHeight());
                                                productInfo.setXiuziZiti(depart_productlist.get(k).getXiuziZiti());
                                                productInfo.setZidingyiImg(depart_productlist.get(k).getZidingyiImg());
                                                productInfo.setZhuangseIds(depart_productlist.get(k).getZhuangseIds());
                                                productInfo.setXiuziOneNeirong(depart_productlist.get(k).getXiuziOneNeirong());
                                                productInfo.setXiuziTwoNeirong(depart_productlist.get(k).getXiuziTwoNeirong());
                                                productInfo.setLibuId(depart_productlist.get(k).getLibuId());
                                                productInfo.setDilinliId(depart_productlist.get(k).getDilinliId());
                                                productInfo.setButtonsIds(depart_productlist.get(k).getButtonsIds());
                                                productInfo.setXiuziPriceId(depart_productlist.get(k).getXiuziPriceId());
                                                productInfo.setBodySizeIds(depart_productlist.get(k).getBodySizeIds());
                                                productInfo.setOldbodySizeIds(depart_productlist.get(k).getOldbodySizeIds());
                                                productInfo.setSizeIds(depart_productlist.get(k).getSizeIds());
                                                int code3 = logicService.insert_products(productInfo);
                                                if(code3>0){
                                                    //执行添加产品到部门
                                                    logicService.add_newdepart_product(product_id,departDetail.getId(),"使用模板创建的产品");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        //创建团订订单
        int code = logicService.insert_team_order(teamOrderInfo);
        if(code>0){
            obj.put("code", 0);
            obj.put("msg", "复制订单成功");
            obj.put("orderSn", order_sn);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "复制订单失败");
            obj.put("orderSn", "0");
            return obj;
        }
//        } catch (Exception e) {
//            obj.put("code", 2);
//            obj.put("msg", "设置失败，参数错误");
//            return obj;
//        }
    }


    /**
     * 根据token统计订单数据
     * @return
     */
    @PostMapping(value = "/count_order_tableData")
    public JSONObject count_order_tableData(String token,String StartTime,String endTime){
        JSONObject obj = new JSONObject();//返回对象
//        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(token,3);
            if(userInfo==null){
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }else {
                 List<String> daytime = new ArrayList<>();//时间
                 List<String> costNum = new ArrayList<>();//笔数
                 List<String> costMoey = new ArrayList<>();//金额
                double summoney = 0;
                SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat f2 = new SimpleDateFormat("MM-dd");
                //根据用户id查询业务流水表
                List<BusinessWaterInfo> businesswaterlist = logicService.query_businesswaterInfo(userInfo.getOrgCode(),StartTime,endTime);
                if(businesswaterlist.size()>0){
                    for (int i=0;i<businesswaterlist.size();i++){
                        //添加时间集合（X轴）
                        daytime.add(f2.format(businesswaterlist.get(i).getCreateTime()));
                        //根据时间查询业务流水表
                        List<BusinessWaterInfo> businesswaterlist2 = logicService.count_businesswaterInfo(f.format(businesswaterlist.get(i).getCreateTime()),userInfo.getId().toString());
                        if(businesswaterlist2.size()>0){
                            //添加笔数集合（y轴1）
                            costNum.add(businesswaterlist2.size()+"");
                            summoney = 0;
                            for (int j=0;j<businesswaterlist2.size();j++){
                                double money = Double.parseDouble(businesswaterlist2.get(j).getCostMoney());
                                summoney+=money;
//                                BusinessWaterInfo businesswaterinfo = logicService.queryOrderMoney(businesswaterlist2.get(j).getOrderId(),businesswaterlist2.get(j).getType());
//                                if(businesswaterinfo!=null){
//                                    double money = Double.parseDouble(businesswaterinfo.getOrdermoney());
//                                    summoney+=money;
//                                }
                            }
                            String zheqian = new DecimalFormat("0.00").format(summoney);
                            //添加金额集合（y轴2）
                            costMoey.add(zheqian);
                        }
                    }
                }
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data1", daytime);
                obj.put("data2", costNum);
                obj.put("data3", costMoey);
                return obj;
            }
//        }catch (Exception e){
//            obj.put("code", 1);
//            obj.put("msg", "查询失败");
//            return obj;
//        }
    }

    /**
     * 查询今日和昨日的流水
     * @return
     */
    @PostMapping(value = "/query_busines_waterInfo")
    public JSONObject query_busines_water(String token,int type){
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token,3);
        if(userInfo==null){
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        Date date=new Date();//取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动
        date=calendar.getTime(); //这个时间就是日期往后推一天的结果
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String yesterday = formatter.format(date);
        String today = formatter.format(new Date());
        DecimalFormat df  = new DecimalFormat("0.00");
        List<BusinessWaterInfo> datalist = new ArrayList<>();
        double sumorder_money=0.0,sumtuikuan_money=0.0;
        int tading_num = 0;
//        System.out.print("前端======================="+type);
        if(type==1){
            datalist = logicService.query_businesswater_today(userInfo.getOrgCode(),today);
            if(datalist.size()>0){
                for (int i=0;i<datalist.size();i++){
                    if(datalist.get(i).getStatus()==3){//退款
                        sumtuikuan_money += Double.parseDouble(datalist.get(i).getReturnMoney());
                        if(datalist.get(i).getType()==0){
                            datalist.get(i).setYewuDeatil("面料下单-已退款");
                        }else if(datalist.get(i).getType()==1){
                            datalist.get(i).setYewuDeatil("个订下单-已退款");
                        }else if(datalist.get(i).getType()==2){
                            datalist.get(i).setYewuDeatil("团订下单-已退款");
                        }else {
                            datalist.get(i).setYewuDeatil("成衣下单-已退款");
                        }
                    }else {
                        sumorder_money += Double.parseDouble(datalist.get(i).getCostMoney());
                        if(datalist.get(i).getType()==0){
                            datalist.get(i).setYewuDeatil("面料下单");
                        }else if(datalist.get(i).getType()==1){
                            datalist.get(i).setYewuDeatil("个订下单");
                        }else if(datalist.get(i).getType()==2){
                            datalist.get(i).setYewuDeatil("团订下单");
                        }else {
                            datalist.get(i).setYewuDeatil("成衣下单");
                        }
                    }
                }
                tading_num = datalist.size();
            }
        }else {
            datalist = logicService.query_businesswater_today(userInfo.getOrgCode(),yesterday);
            if(datalist.size()>0){
                for (int i=0;i<datalist.size();i++){
                    if(datalist.get(i).getStatus()==3){//退款
                        sumtuikuan_money += Double.parseDouble(datalist.get(i).getReturnMoney());
                        if(datalist.get(i).getType()==0){
                            datalist.get(i).setYewuDeatil("面料下单-已退款");
                        }else if(datalist.get(i).getType()==1){
                            datalist.get(i).setYewuDeatil("个订下单-已退款");
                        }else if(datalist.get(i).getType()==2){
                            datalist.get(i).setYewuDeatil("团订下单-已退款");
                        }else {
                            datalist.get(i).setYewuDeatil("成衣下单-已退款");
                        }
                    }else {
                        sumorder_money += Double.parseDouble(datalist.get(i).getCostMoney());
                        if(datalist.get(i).getType()==0){
                            datalist.get(i).setYewuDeatil("面料下单");
                        }else if(datalist.get(i).getType()==1){
                            datalist.get(i).setYewuDeatil("个订下单");
                        }else if(datalist.get(i).getType()==2){
                            datalist.get(i).setYewuDeatil("团订下单");
                        }else {
                            datalist.get(i).setYewuDeatil("成衣下单");
                        }
                    }
                }
                tading_num = datalist.size();
            }
        }
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            obj.put("sumorder_money", df.format(sumorder_money));
            obj.put("sumtuikuan_money", df.format(sumtuikuan_money));
            obj.put("tading_num", tading_num);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "查询失败");
            return obj;
        }
    }

    /**
     * 个订-复制订单/再来一单
     * @return
     */
    @PostMapping(value = "/copy_order")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_copy_order(SingleOrderInfo orderInfo) {
        JSONObject obj = new JSONObject();//返回对象
//        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(orderInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            if (orderInfo.getOrderSn() == null || "".equals(orderInfo.getOrderSn())) {
                obj.put("code", 3);
                obj.put("msg", "订单编号不能为空");
                return obj;
            }
            //新的订单
            SingleOrderInfo orderInfo2 = new SingleOrderInfo();
            //新的模板
            TemplateRecordInfo templateInfo2 = new TemplateRecordInfo();
            //获取汉子的首字母
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            WordUtils word = new WordUtils();
            String zimuname = word.getUpperCase(userInfo.getRealname(),false);
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(100000)+1;//为变量赋随机值1-99999999;
            String order_sn = "S"+zimuname+(startTs.toString())+random;
            String template_sn = "SINGLE"+(startTs.toString())+random;
            //订单信息
            orderInfo2.setOrderSn(order_sn);
            orderInfo2.setUserId(userInfo.getId().toString());
            //模板信息
            templateInfo2.setOrderSn(template_sn);
            templateInfo2.setUserId(userInfo.getId().toString());

            if(orderInfo.getOrderName()==null || "".equals(orderInfo.getOrderName())){
                orderInfo2.setOrderName(f.format(new Date())+"订单");
                templateInfo2.setTemplateName(f.format(new Date())+"个订模板");
            }
            String oldproductid ="";
            //根据订单编号查询模板信息（这是原订单）
            SingleOrderInfo templateInfo = logicService.query_signorder(orderInfo.getOrderSn());
            if(templateInfo!=null){
                //订单信息
                orderInfo2.setOrderName(templateInfo.getOrderName());//订单名字
                orderInfo2.setStoreId(templateInfo.getStoreId());//门店id
                orderInfo2.setStoreCode(templateInfo.getStoreCode());//门店编码
                orderInfo2.setCustomerCode(templateInfo.getCustomerCode());//客户编码
                orderInfo2.setCustomerName(templateInfo.getCustomerName());//客户名称
                orderInfo2.setCustomerSex(templateInfo.getCustomerSex());//客户性别
                orderInfo2.setFabricSource(templateInfo.getFabricSource());//面料来源
                orderInfo2.setBusinessSource(templateInfo.getBusinessSource());//业务来源
                orderInfo2.setPackageType(templateInfo.getPackageType());//包装方式
                orderInfo2.setCourierId(templateInfo.getCourierId());//快递id
                orderInfo2.setAddressType(templateInfo.getAddressType());//地址类型
                orderInfo2.setAddress(templateInfo.getAddress());//地址
                orderInfo2.setThirdSn(templateInfo.getThirdSn());//第三方运单号
                orderInfo2.setStatus(0);
                orderInfo2.setOrderMoney(templateInfo.getOrderMoney());
                orderInfo2.setSysOrgCode(userInfo.getOrgCode());
                //模板信息
                templateInfo2.setTemplateName(templateInfo.getOrderName());
                templateInfo2.setStoreId(templateInfo.getStoreId());
                templateInfo2.setStoreCode(templateInfo.getStoreCode());//门店编码
                templateInfo2.setKuhuCode(templateInfo.getCustomerCode());//客户编码
                templateInfo2.setKuhuName(templateInfo.getCustomerName());//客户名称
                templateInfo2.setKuhuSex(templateInfo.getCustomerSex());//客户性别
                templateInfo2.setMianliaoSource(templateInfo.getFabricSource());//面料来源
                templateInfo2.setYewuType(templateInfo.getBusinessSource());//业务来源
                templateInfo2.setPackageType(templateInfo.getPackageType());//包装方式
                templateInfo2.setKuaidiId(templateInfo.getCourierId());//快递id
                templateInfo2.setAddressType(templateInfo.getAddressType());//地址类型
                templateInfo2.setAddress(templateInfo.getAddress());//地址
                templateInfo2.setThirdSn(templateInfo.getThirdSn());//第三方运单号
                templateInfo2.setCompanyCode(userInfo.getCompanyOrgcode());
                templateInfo2.setStatus(1);
                templateInfo2.setSysOrgCode(userInfo.getOrgCode());

                //老订单里面的产品ids
                if(templateInfo.getChanpingIds()!=null && !"".equals(templateInfo.getChanpingIds())){
                    String chanpinids[] = templateInfo.getChanpingIds().split(",");
                    String productids ="";
                    for (String s:chanpinids){
                        ProductInfo productInfo1 = logicService.query_productDetail(s);
                        //产品表
                        SimpleDateFormat f2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        if(productInfo1.getProductName()==null || "".equals(productInfo1.getProductName())){
                            productInfo1.setProductName(f2.format(new Date())+"产品");
                        }
                        //获取汉子的首字母
                        WordUtils word2 = new WordUtils();
                        String zimuname2 = word2.getUpperCase(userInfo.getRealname(),false);
                        Long startTs2 = System.currentTimeMillis(); // 当前时间戳
                        //8位随机数
                        int random2=new Random().nextInt(10000000)+1;//为变量赋随机值1-99999999;
                        String productSn = zimuname2+(startTs2.toString());
                        String productId = startTs.toString()+random2;
                        System.out.print("产品主键==="+productId+"==="+random2);
                        //赋值产品货号
                        productInfo1.setProductCode(productSn);
                        //赋值产品id
                        productInfo1.setId(productId);
                        //赋值用户id
                        productInfo1.setUserId(userInfo.getId().toString());
                        //产品类型
                        productInfo1.setProductType(0);
                        productInfo1.setOrderSn(order_sn);//订单编号
                        productInfo1.setTemplateSn(template_sn);//模板编号
                        if(productInfo1.getOldbodySizeIds()!=null && !"".equals(productInfo1.getOldbodySizeIds())){
                            //拿到前端传入的尺寸值尚未变化之前的
                            String size1[] = productInfo1.getOldbodySizeIds().split(",");
                            for (String s2:size1){
                                String size2[] = s2.split("/");
                                logicService.add_Order_sizeInfo(productId,size2[0],size2[1],"0",new Date());
                            }
                        }
                        //创建新产品
                        int code = logicService.insert_products(productInfo1);
                        if(code>0){
                            productids+=productId+",";
                            System.out.print("产品创建成功");
                        }else {
                            System.out.print("产品创建失败");
                        }
                    }
                    oldproductid = productids.substring(0,productids.length()-1);
                    orderInfo2.setChanpingIds(oldproductid);
                    templateInfo2.setChanpinIds(oldproductid);
                    System.out.print("老订单产品主键22==="+oldproductid+"==="+productids);
                }
            }
            String chanpinids2[] = oldproductid.split(",");
            //创建个订新订单
            int code = logicService.add_signOrderInfo(orderInfo2);
            //创建个订新模板
            int code2 = logicService.add_templateInfo(templateInfo2);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "复制订单成功");
                obj.put("productId", chanpinids2[0]);
                obj.put("order_sn", order_sn);
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "复制订单失败");
                obj.put("productId","0");
                obj.put("order_sn", "0");
                return obj;
            }
//        } catch (Exception e) {
//            obj.put("code", 2);
//            obj.put("msg", "复制失败，请重新创建");
//            obj.put("order_sn", "0");
//            return obj;
//        }
    }

    /**
     * 根据用户id查询流水列表
     * @return
     */
    @PostMapping(value = "/query_myWaterlist")
    public JSONObject post_query_myWaterlist(@RequestParam(name="token") String token,
                                             @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                             @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                             int type) {
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        Page<BusinessWaterInfo> page = new Page<BusinessWaterInfo>(pageNo, pageSize);
        IPage<BusinessWaterInfo> pageList = logicService.query_yewu_waterInfo(page,userInfo.getId().toString(),type);
        if(pageList != null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", pageList);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", pageList);
            return obj;
        }
    }


    /**
     * 团定下面创建产品---直接添加到部门
     * @return
     */
    @PostMapping(value = "/add_products_todepart")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_add_products_todepart(ProductInfo productInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(productInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            if (productInfo.getDepartId() == null || "".equals(productInfo.getDepartId())) {
                obj.put("code", 5);
                obj.put("msg", "部门id不能为空");
                return obj;
            }
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            int random2=new Random().nextInt(1000)+1;
            String productSn = UUID.randomUUID().toString().substring(0,10)+random2;
//            String productSn = "CPH"+(startTs.toString());
            String productId = startTs.toString()+random;
            //赋值产品货号
            productInfo.setProductCode(productSn);
            //赋值产品id
            productInfo.setId(productId);
            //赋值用户id
            productInfo.setUserId(userInfo.getId().toString());
            //产品类型
            productInfo.setProductType(2);

            double lost_price1=0,lost_price2=0;//最终价格
            //拿到类别id
            if(productInfo.getCategoryIds()!=null && !"".equals(productInfo.getCategoryIds())){
                System.out.print("传进来的类别id==="+productInfo.getCategoryIds());
                String pinglei[] = productInfo.getCategoryIds().split(",");
                List<String> resultList= new ArrayList<>(Arrays.asList(pinglei));
                double cost = 0,zhe_price=0;
                String categoryImg = "";
                if(resultList.size()>=1 && resultList.size()<2){
                    //拿到类别名称和价格
                    CategoryInfo categoryInfodetail = logicService.query_categoryDetailInfo(resultList.get(0));
                    if(categoryInfodetail!=null){
                        categoryImg = categoryInfodetail.getImg();
                        if("女装".equals(categoryInfodetail.getCategoryName())){
                            productInfo.setSex(1);
                        }else {
                            productInfo.setSex(0);
                        }
                    }
                }else if(resultList.size()>=2){
                    //拿到类别名称和价格
                    CategoryInfo categoryInfodetail2 = logicService.query_categoryDetailInfo(resultList.get(0));
                    CategoryInfo categoryInfodetail = logicService.query_categoryDetailInfo(resultList.get(1));
                    if(categoryInfodetail!=null){
                        categoryImg = categoryInfodetail.getImg();
                    }
                    if("女装".equals(categoryInfodetail2.getCategoryName())){
                        productInfo.setSex(1);
                    }else {
                        productInfo.setSex(0);
                    }
                    if(productInfo.getProductName()==null || "".equals(productInfo.getProductName())){
                        productInfo.setProductName(categoryInfodetail.getCategoryName()+"-"+categoryInfodetail.getCategoryCode());
                    }else {
                        productInfo.setProductName(productInfo.getProductName());
                    }
                }
                productInfo.setProductImg(categoryImg);
            }
            //查询纽扣价格
//            if(productInfo.getButtonsIds()!=null && !"".equals(productInfo.getButtonsIds())){
//                double cost = 0,zhe_price=0;
//                ButtonsInfo buttonsInfo = logicService.query_buttonsInfo(productInfo.getButtonsIds());
//                if(buttonsInfo!=null){
//                    cost = Double.parseDouble(buttonsInfo.getRetailPrice());//零售价
//                    //纽扣暂没折扣价
//                    lost_price1+=cost;
//                    lost_price2+=zhe_price;
//                }
//            }
            //格式化类
            String zheqian = new DecimalFormat("0.00").format(lost_price1);
            String zhehou = new DecimalFormat("0.00").format(lost_price2);
            productInfo.setZheqianPrice(0.00);
            productInfo.setZhehouPrice(0.00);

//            if(productInfo.getBodySizeIds()!=null && !"".equals(productInfo.getBodySizeIds())){
//                //获取前端传过来的尺寸ids
//                String oldbody_sizes = productInfo.getBodySizeIds();
//                //拿到前端传入的尺寸值
//                String bodysize1[] = productInfo.getBodySizeIds().split(",");
//                String strbody="";
//                for (String s:bodysize1){
//                    String size2[] = s.split("/");
//                    strbody+=size2[0]+",";
//                }
//                String bodysizes = strbody.substring(0,strbody.length()-1);
//                productInfo.setBodySizeIds(bodysizes);
//                productInfo.setOldbodySizeIds(oldbody_sizes);//变化之前的
//                //拿到前端传入的尺寸值尚未变化之前的
//                String size1[] = oldbody_sizes.split(",");
//                for (String s:size1){
//                    String size2[] = s.split("/");
//                    List<BodySizeInfo> bodySizeInfos = logicService.query_bodySizeinfo_productid(productInfo.getId(),size2[0],size2[1]);
//                    if(bodySizeInfos.size()<=0){
//                        logicService.add_Order_sizeInfo(productInfo.getId(),size2[0],size2[1],"0",new Date());
//                    }
//                }
//            }
            //添加产品
            int code = logicService.insert_products(productInfo);
            int code2 = logicService.insert_products_todepart(productId,productInfo.getDepartId(),new Date());
            if(code>0 && code2>0){
                obj.put("code", 0);
                obj.put("msg", "产品已添加成功!");
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "添加产品失败");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "添加产品失败，请重新创建");
            return obj;
        }
    }

    /**
     * 团订下的量体信息--保存用户的量体信息
     * @return
     */
    @PostMapping(value = "/save_team_userLiangtiInfo")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject save_team_userLiangtiInfo(SmallProductInfo dataInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(dataInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            int random2=new Random().nextInt(1000)+1;
            String productSn = UUID.randomUUID().toString().substring(0,12)+random2;
            String productId = startTs.toString()+random;
            //先查询
            SmallProductInfo datainfo2 = logicService.query_smallProductInfo(dataInfo.getTeamOrderSn(),dataInfo.getProductId(),dataInfo.getCustomerId());
            if(datainfo2!=null){
                if(dataInfo.getBodySizeIds()!=null && !"".equals(dataInfo.getBodySizeIds())){
                    //获取前端传过来的尺寸ids
                    String oldbody_sizes = dataInfo.getBodySizeIds();
                    //拿到前端传入的尺寸值
                    String bodysize1[] = dataInfo.getBodySizeIds().split(",");
                    String strbody="";
                    for (String s:bodysize1){
                        String size2[] = s.split("/");
                        if(size2==null || "".equals(size2[0]) || "".equals(size2[1]) || size2[1]==null || "null".equals(size2[1])){
                            size2[1]="";
                        }
                        strbody+=size2[0]+",";
                        int code2 = logicService.update_smallproduct_bodysizes(dataInfo.getTeamOrderSn(),datainfo2.getId(),size2[0],size2[1],0);
                        System.out.println("修改小产品尺寸=="+code2);
                    }
                    String bodysizes = strbody.substring(0,strbody.length()-1);
                    dataInfo.setBodySizeIds(bodysizes);
                    dataInfo.setOldBodysizeIds(oldbody_sizes);//变化之前的
                }else {
                    if("1".equals(dataInfo.getBodysType().toString()) && datainfo2.getBodysType()==0){
                        //获取前端传过来的尺寸ids
                        String oldbody_sizes = datainfo2.getOldBodysizeIds();
                        //拿到前端传入的尺寸值
                        String bodysize1[] = oldbody_sizes.split(",");
                        dataInfo.setOldBodysizeIds(oldbody_sizes);
                        for (String s:bodysize1){
                            String size2[] = s.split("/");
                            int code2 = logicService.update_smallproduct_bodysizes(dataInfo.getTeamOrderSn(),datainfo2.getId(),size2[0],size2[1],1);
                            System.out.println("删除小产品尺寸=="+code2);
                        }
                    }
                }
                dataInfo.setRemark("临时修改客户身体数据");
                //执行修改
                int code = logicService.update_teamOrder_products(dataInfo);
                if(code>0){
                    obj.put("code", 0);
                    obj.put("msg", "保存成功");
                    return obj;
                }else {
                    obj.put("code", 1);
                    obj.put("msg", "保存失败");
                    return obj;
                }
            }else {
                //计算小产品售价
//                ProductInfo productInfo = logicService.query_productDetail(dataInfo.getProductId());
//                if(productInfo!=null){
//                    if(productInfo.getT)
//                }

                //赋值小产品货号
                dataInfo.setCode(productSn);
                //赋值小产品id
                dataInfo.setId(productId);
                if(dataInfo.getBodySizeIds()!=null && !"".equals(dataInfo.getBodySizeIds())){
                    //获取前端传过来的尺寸ids
                    String oldbody_sizes = dataInfo.getBodySizeIds();
                    //拿到前端传入的尺寸值
                    String bodysize1[] = dataInfo.getBodySizeIds().split(",");
                    String strbody="";
                    for (String s:bodysize1){
                        String size2[] = s.split("/");
                        if(size2==null || "".equals(size2[0]) || "".equals(size2[1]) || size2[1]==null || "null".equals(size2[1])){
                            size2[1]="";
                        }
                        strbody+=size2[0]+",";
                        int code2 = logicService.insert_smallproduct_bodysizes(dataInfo.getTeamOrderSn(),productId,size2[0],size2[1]);
                        System.out.println("小产品尺寸=="+code2);
                    }
                    String bodysizes = strbody.substring(0,strbody.length()-1);
                    dataInfo.setBodySizeIds(bodysizes);
                    dataInfo.setOldBodysizeIds(oldbody_sizes);//变化之前的
                }
                //再创建小产品
                int code = logicService.insert_teamOrder_products(dataInfo);
                if(code>0){
                    obj.put("code", 0);
                    obj.put("msg", "保存成功");
                    return obj;
                }else {
                    obj.put("code", 1);
                    obj.put("msg", "保存失败");
                    return obj;
                }
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "设置失败，参数错误");
            return obj;
        }
    }

    /**
     * 根据团订下的客户id和客户编码查询客户信息
     * @return
     */
    @PostMapping(value = "/query_customerDetailById")
    public JSONObject query_customerDetailById(String customerId,String code){
        JSONObject obj = new JSONObject();//返回对象
        CustomerInfo datainfo = logicService.queryCostomerDtailById(customerId,code);
        if(datainfo!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datainfo);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datainfo);
            return obj;
        }
    }

    /**
     * 根据部门id查询部门下的产品
     * @return
     */
    @PostMapping(value = "/query_productsBydepartId")
    public JSONObject query_productsBydepartId(String departId,String sex){
        JSONObject obj = new JSONObject();//返回对象
        String sex_p = "0";
        if("1".equals(sex)){
            sex_p = "0";
        }else if("2".equals(sex)){
            sex_p = "1";
        }else {
            sex_p = "11";
        }
        List<ProductInfo> datalist = logicService.query_allproductBydepartId(departId,sex_p);
        if(datalist.size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }


    /**
     * 根据产id查询部门下的产品详情
     * @return
     */
    @PostMapping(value = "/query_productDetailById")
    public JSONObject query_productDetailById(String productId){
        JSONObject obj = new JSONObject();//返回对象
        ProductInfo datalist = logicService.query_productDetail(productId);
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /**
     * 删除部门下的产品
     * @return
     */
    @PostMapping(value = "/delete_depart_products")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject delete_depart_products(String id,String product_id){
        JSONObject obj = new JSONObject();//返回对象
        try {
            int code = logicService.delete_depart_product(id,product_id);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "你已成功删除该产品");
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "删除失败");
                return obj;
            }
        }catch (Exception e){
            obj.put("code", 2);
            obj.put("msg", "删除失败，请稍后刷新重试");
            return obj;
        }
    }

    /**
     * 团定下面-复制产品信息
     * @return
     */
    @PostMapping(value = "/copy_departproducts")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_copy_departproducts(ProductInfo productInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(productInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(100000)+1;//为变量赋随机值1-99999999;
            int random2=new Random().nextInt(1000)+1;
            String productSn = UUID.randomUUID().toString().substring(0,10)+random2;
            String productId = startTs.toString()+random;
            //根据产品id查询产品详情
            ProductInfo old_productInfo1 = logicService.query_productDetail(productInfo.getId());
            System.out.println("avdadv==="+old_productInfo1);
            if(old_productInfo1!=null){
                //转移产品信息
                productInfo.setProductName(old_productInfo1.getProductName()+productSn);
                productInfo.setProductImg(old_productInfo1.getProductImg());
                productInfo.setSex(old_productInfo1.getSex());
                productInfo.setProductType(0);//产品类型
                productInfo.setStatus(0);
                productInfo.setZheqianPrice(0.0);
                productInfo.setZhehouPrice(0.0);
                productInfo.setCategoryIds(old_productInfo1.getCategoryIds());
                productInfo.setFabricIds(old_productInfo1.getFabricIds());
                productInfo.setXiuziPriceId(old_productInfo1.getXiuziPriceId());
                productInfo.setXiuziType(old_productInfo1.getXiuziType());
                productInfo.setXiuziWeizhi(old_productInfo1.getXiuziWeizhi());
                productInfo.setXiuziImg(old_productInfo1.getXiuziImg());
                productInfo.setXiuziColor(old_productInfo1.getXiuziColor());
                productInfo.setXiuziHeight(old_productInfo1.getXiuziHeight());
                productInfo.setZidingyiImg(old_productInfo1.getZidingyiImg());
                productInfo.setXiuziZiti(old_productInfo1.getXiuziZiti());
                productInfo.setXiuziOneNeirong(old_productInfo1.getXiuziOneNeirong());
                productInfo.setXiuziTwoNeirong(old_productInfo1.getXiuziTwoNeirong());
                productInfo.setZhuangseIds(old_productInfo1.getZhuangseIds());
                productInfo.setButtonsIds(old_productInfo1.getButtonsIds());
                productInfo.setLibuId(old_productInfo1.getLibuId());
                productInfo.setDilinliId(old_productInfo1.getDilinliId());
                productInfo.setRemark(old_productInfo1.getRemark());
                productInfo.setNumbers(1);
            }
            //赋值产品货号
            productInfo.setProductCode(productSn);
            //赋值产品id
            productInfo.setId(productId);
            //赋值用户id
            productInfo.setUserId(userInfo.getId().toString());
            //添加产品
            int code = logicService.insert_products(productInfo);
            int code2 = logicService.insert_products_todepart(productId,productInfo.getDepartId(),new Date());
            if(code>0 && code2>0){
                obj.put("code", 0);
                obj.put("msg", "产品复制成功!");
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "复制产品失败");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "复制产品失败，请重新复制");
            return obj;
        }
    }

    /**
     * 团定下面-修改产品信息
     * @return
     */
    @PostMapping(value = "/edit_departproducts_name")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_edit_departproducts_name(String id,String productName){
        JSONObject obj = new JSONObject();//返回对象
        try {
            if(productName==null || "".equals(productName)){
                obj.put("code", 3);
                obj.put("msg", "产品名称不能为空");
                return obj;
            }
            //编辑产品
            int code = logicService.update_only_productsName(id,productName);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "产品修改成功!");
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "修改产品失败");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "修改产品失败，请重新修改");
            return obj;
        }
    }

    /**
     * 根据客户id查询用户量体列表
     * @return
     */
    @PostMapping(value = "/query_lianngtiListBycustomerId")
    public JSONObject query_lianngtiListBycustomerId(@RequestParam(name="token") String token,
                                             @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                             @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                             String partmentId,String queryName, int is_liangti) {
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        Page<CustomerInfo> page = new Page<CustomerInfo>(pageNo, pageSize);
        IPage<CustomerInfo> pageList = logicService.query_customer_liangti(page,partmentId,queryName,is_liangti);
        if(pageList.getRecords().size()>0){
            for (int i = 0;i<pageList.getRecords().size();i++){
                if(pageList.getRecords().get(i).getSmallproductId()!=null && !"".equals(pageList.getRecords().get(i).getSmallproductId())){
                    pageList.getRecords().get(i).setLiangtiStatus("已完成");
                }else {
                    pageList.getRecords().get(i).setLiangtiStatus("未完成");
                }
            }
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", pageList);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", pageList);
            return obj;
        }
    }

    /**
     * 删除小产品信息---如果有量体顺带删除量体信息
     * @return
     */
    @PostMapping(value = "/delete_smallproducts_bodysize")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_delete_smallproducts_bodysize(String smallproductId){
        JSONObject obj = new JSONObject();//返回对象
        try {
            if(smallproductId==null || "".equals(smallproductId)){
                obj.put("code", 3);
                obj.put("msg", "id不能为空");
                return obj;
            }
            int code = logicService.delete_small_product(smallproductId);
            if(code>0){
                obj.put("code", 0);
                obj.put("msg", "操作成功!");
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "操作失败");
                return obj;
            }
        } catch (Exception e) {
            obj.put("code", 2);
            obj.put("msg", "操作失败，请重新修改");
            return obj;
        }
    }

    /**
     * 根据客户id，大产品id，订单编号查询小产品详情
     * @return
     */
    @PostMapping(value = "/query_smallproductInfoByType")
    public JSONObject query_smallproductInfoByType(String customerId,String productId,String orderSn){
        JSONObject obj = new JSONObject();//返回对象
        SmallProductInfo datainfo = logicService.query_smallproductInfoByType(customerId,productId,orderSn);
        if(datainfo!=null){
            if(datainfo.getBodysType()==0){//0自定义尺码，1标准尺码
                if(datainfo.getOldBodysizeIds() != null && !"".equals(datainfo.getOldBodysizeIds())){
                    //拿到前端传入的尺寸值
                    String bodysize1[] = datainfo.getOldBodysizeIds().split(",");
                    List<BodySizeInfo> datalist1 = new ArrayList<>();
                    List<BodySizeInfo> datalist2 = new ArrayList<>();
                    for (String s:bodysize1){
                        String size2[] = s.split("/");
                        System.out.println("尺寸id==="+size2[0]+"===="+size2[1]);
                        BodySizeInfo bodySizeInfo = logicService.query_bodySizeInfoByid(size2[0]);
                        if(bodySizeInfo!=null){
                            if(bodySizeInfo.getIsJin()==0){//0普通尺寸，1斤体尺寸
                                BodySizeInfo bodySizeInfo1 = new BodySizeInfo();
                                bodySizeInfo1.setBodySizename(bodySizeInfo.getBodySizename());
                                bodySizeInfo1.setId(bodySizeInfo.getId());
                                bodySizeInfo1.setIsJin(bodySizeInfo.getIsJin());
                                bodySizeInfo1.setMin(bodySizeInfo.getMin());
                                bodySizeInfo1.setMax(bodySizeInfo.getMax());
                                bodySizeInfo1.setUnit(bodySizeInfo.getUnit());
                                bodySizeInfo1.setIsBitian(bodySizeInfo.getIsBitian());
                                if(size2[1]==null || "".equals(size2[1]) || "null".equals(size2[1])){
                                    bodySizeInfo1.setBodySizevalue(" ");
                                }else {
                                    bodySizeInfo1.setBodySizevalue(size2[1]);
                                }
                                datalist1.add(bodySizeInfo1);
                            }else {
                                BodySizeInfo bodySizeInfo2 = new BodySizeInfo();
                                bodySizeInfo2.setBodySizename(bodySizeInfo.getBodySizename());
                                bodySizeInfo2.setId(bodySizeInfo.getId());
                                bodySizeInfo2.setIsJin(bodySizeInfo.getIsJin());
                                bodySizeInfo2.setMin(bodySizeInfo.getMin());
                                bodySizeInfo2.setMax(bodySizeInfo.getMax());
                                bodySizeInfo2.setUnit(bodySizeInfo.getUnit());
                                bodySizeInfo2.setIsBitian(bodySizeInfo.getIsBitian());
                                if(size2[1]==null || "".equals(size2[1]) || "null".equals(size2[1])){
                                    bodySizeInfo2.setBodySizevalue(" ");
                                }else {
                                    bodySizeInfo2.setBodySizevalue(size2[1]);
                                }
                                datalist2.add(bodySizeInfo2);
                            }
                            datainfo.setBodySizeInfoList1(datalist1);
                            datainfo.setBodySizeInfoList2(datalist2);
                        }
                    }
                }
            }
            //图片集合
            if(datainfo.getLiangtiImgs()!=null || !"".equals(datainfo.getLiangtiImgs())){
                String imgs[] = datainfo.getLiangtiImgs().split(",");
                List<String> imglist1 = new ArrayList<>();
                for (String s:imgs){
                    imglist1.add(s);
                }
                datainfo.setImglists(imglist1);
            }
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datainfo);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datainfo);
            return obj;
        }
    }

    /**
     * 根据团订下的客户id查询客户信息（这里是公司身份）
     * @return
     */
    @PostMapping(value = "/query_customerInfoById")
    public JSONObject query_customerInfoById(String customerId){
        JSONObject obj = new JSONObject();//返回对象
        CustomerInfo datainfo = logicService.queryCostomerInfoById(customerId);
        if(datainfo!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datainfo);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datainfo);
            return obj;
        }
    }


    /**
     * 我的消息列表
     * @return
     */
    @PostMapping(value = "/query_mymessage")
    public JSONObject query_mymessage(@RequestParam(name="token") String token,String queryName,String is_read){
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        List<MessageDataInfo2> datalist = logicService.query_mymessage(queryName,is_read,userInfo.getId().toString());
        if(datalist.size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }
    /**
     * 我的消息详情
     * @return
     */
    @PostMapping(value = "/query_messageDetail")
    public JSONObject query_messageDetail(@RequestParam(name="msg_id") String msg_id){
        JSONObject obj = new JSONObject();//返回对象
        MessageDataInfo2 datalist = logicService.query_messageDetail(msg_id);
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /**
     * 是否已读
     * @return
     */
    @PostMapping(value = "/add_read_message")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject add_read_message(@RequestParam(name="msg_id") String msg_id,
                                       @RequestParam(name="token") String token){
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
//        try {
            MessageDataInfo2 message = logicService.query_read_messageDetail(msg_id,userInfo.getId().toString());
            if(message==null || "".equals(message)){
                int code = logicService.add_readed_message(msg_id,userInfo.getId().toString(),"2");
                if(code>0){
                    obj.put("code", 0);
                    obj.put("msg", "查看成功");
                    return obj;
                }else {
                    obj.put("code", 1);
                    obj.put("msg", "查看失败");
                    return obj;
                }
            }else {
                obj.put("code", 1);
                obj.put("msg", "你已看过该信息");
                return obj;
            }
//        }catch (Exception e){
//            obj.put("code", 2);
//            obj.put("msg", "查看失败，请稍后刷新重试");
//            return obj;
//        }
    }


    /**
     * 查询系统加急项
     * type：4式样，5紧急指数，6改款打样
     * order_type：默认0个订业务，1团订业务，2标准码业务
     * @return
     */
    @PostMapping(value = "/query_system_addpriceInfo")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject query_system_addpriceInfo(@RequestParam(name="order_type") String order_type,
                                                @RequestParam(name="product_id") String product_id){
        JSONObject obj = new JSONObject();//返回对象
        if (product_id == null || "".equals(product_id)) {
            obj.put("code", 3);
            obj.put("msg", "产品id不能为空");
            return obj;
        }
        //根据产品id查询类别ids
        ProductInfo productInfo = logicService.query_productDetail(product_id);
        String pinglei_id = "";//品类id
        if(productInfo != null) {
            String categoryIds = productInfo.getCategoryIds();
            //拿到类别ids
            String pingleis[] = categoryIds.split(",");
            for (String s : pingleis) {
                CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
                if (categoryInfo != null) {
                    if (categoryInfo.getIsType() == 2) {
                        pinglei_id = categoryInfo.getId().toString();
                        break;
                    }
                }
            }
//            List<AddSystemPriceInfo> SystemPriceList = new ArrayList<>();
            List<PriceTopSystemInfo> topsyslist = logicService.query_system_ToppriceInfo(pinglei_id);
            if (topsyslist.size() > 0) {
                for (int i = 0; i < topsyslist.size(); i++) {
                    //根据品类id查询系统加价项
                    List<AddSystemPriceInfo> SystemPriceList = logicService.query_system_priceInfo(pinglei_id, topsyslist.get(i).getId().toString());
                    if (SystemPriceList.size() > 0) {
                        //拿到价格体系id
                        MlccPriceSystemPinglei2 mlccPriceSystemPinglei2 = logicService.query_pricepinglei(pinglei_id, order_type, "0");
                        if (mlccPriceSystemPinglei2 != null) {
                            for (int j = 0; j < SystemPriceList.size(); j++) {
                                System.out.println(pinglei_id+"==没亚欧2==="+SystemPriceList.get(j).getId().toString()+"==="+mlccPriceSystemPinglei2.getId().toString());
                                MlccPriceSystemCostRecord priceinfo = logicService.query_pricepinglei_CostRecord(pinglei_id, mlccPriceSystemPinglei2.getId().toString(), SystemPriceList.get(j).getId().toString());
                                if (priceinfo != null) {
                                    System.out.println("有空了==="+priceinfo.getId().toString());
                                    SystemPriceList.get(j).setPrice(priceinfo.getPrice());
                                    SystemPriceList.get(j).setCostId(priceinfo.getId().toString());
                                }else {
//                                    System.out.println("shi拉山口==="+SystemPriceList.size());
//                                    SystemPriceList.remove(j);
                                }
                            }
                        } else {
                            System.out.println("没亚欧===");
                        }
                    }
                    topsyslist.get(i).setAddSystemPriceInfoList(SystemPriceList);
                }
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", topsyslist);
                return obj;
            } else {
                obj.put("code", 1);
                obj.put("msg", "暂无数据");
                obj.put("data", topsyslist);
                return obj;
            }
//            List<AddSystemPriceInfo> SystemPriceList = logicService.query_system_priceInfo(pinglei_id,type);
        }else {
            obj.put("code", 2);
            obj.put("msg", "暂无该产品");
            return obj;
        }
    }


    /**
     * 根据用户id查询团订订单列表---复制订单
     * @return
     */
    @PostMapping(value = "/query_myTeamOrderlist")
    public JSONObject query_myTeamOrderlist(@RequestParam(name="token") String token,
                                             @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                             @RequestParam(name="pageNo", defaultValue="1") Integer pageNo
                                             ,String queryTime,String queryName) {
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        Page<TeamOrderInfo> page = new Page<TeamOrderInfo>(pageNo, pageSize);
        IPage<TeamOrderInfo> pageList = logicService.query_teamOrderInfo(page,userInfo.getOrgCode(),queryTime,queryName);
        if(pageList != null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", pageList);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", pageList);
            return obj;
        }
    }

    /**
     * 根据用户id查询个订订单列表---复制订单
     * @return
     */
    @PostMapping(value = "/query_mySingOrderlist")
    public JSONObject query_mySingOrderlist(@RequestParam(name="token") String token,
                                            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo
                                            ,String queryTime,String queryName) {
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        Page<SingleOrderInfo> page = new Page<SingleOrderInfo>(pageNo, pageSize);
        IPage<SingleOrderInfo> pageList = logicService.query_singleOrderInfo(page,userInfo.getOrgCode(),queryTime,queryName);
        if(pageList != null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", pageList);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", pageList);
            return obj;
        }
    }

    /**
     * 根据类别ids查询1底领尼，0里布，2纽扣
     * @return
     */
    @PostMapping(value = "/query_materialList")
    public JSONObject query_materialList(@RequestParam(name="categoryIds") String categoryIds,@RequestParam(name="type")String type){
        JSONObject obj = new JSONObject();//返回对象
        String banhao_id = "";
        //拿到类别ids
        String pingleis[] = categoryIds.split(",");
        for (String s:pingleis){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==3){
                    banhao_id = categoryInfo.getId().toString();
                    break;
                }
            }
        }
        List<CategoryMaterialInfo> datalist = logicService.query_alllibuListBycategoryId(banhao_id,type);
        if(datalist.size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /** 分页查询
     * 根据类别ids查询1底领尼，0里布，2纽扣
     * @return
     */
    @PostMapping(value = "/query_materialPageList")
    public JSONObject query_materialPageList(
            @RequestParam(name="categoryIds") String categoryIds,
            @RequestParam(name="type")String type,
            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            String code,String buttontype){
        System.out.println("传进来的类别IDS是空的？=="+categoryIds);
        JSONObject obj = new JSONObject();//返回对象
        String banhao_id = "";
        //拿到类别ids
        String pingleis[] = categoryIds.split(",");
        for (String s:pingleis){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==3){
                    banhao_id = categoryInfo.getId().toString();
                    break;
                }
            }
        }
        Page<CategoryMaterialInfo> page = new Page<CategoryMaterialInfo>(pageNo, pageSize);
        System.out.println("拿到的版号id=="+banhao_id);
        IPage<CategoryMaterialInfo> datalist = logicService.query_MaterialInfopageList(page,banhao_id,type,code,buttontype);
        if(datalist.getRecords().size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /** 分页查询
     * 根据类别ids查询绣字图片/字体+分页
     * @return
     */
    @PostMapping(value = "/query_xiuziImgPageList")
    public JSONObject query_xiuziImgPageList(
            @RequestParam(name="category_ids") String category_ids,
            @RequestParam(name="type")String type,
            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            String code){
        System.out.println("传进来的类别IDS是空的？=="+category_ids);
        JSONObject obj = new JSONObject();//返回对象
        String pinglei_id = "";
        //拿到类别ids
        String pingleis[] = category_ids.split(",");
        for (String s:pingleis){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==3){
                    pinglei_id = categoryInfo.getId().toString();
                    break;
                }
            }
        }
        Page<EmbroideredFontInfo> page = new Page<EmbroideredFontInfo>(pageNo, pageSize);
        System.out.println("拿到的版号id=="+pinglei_id);
        IPage<EmbroideredFontInfo> datalist = logicService.query_xiuziImgpageList(page,pinglei_id,type,code);
        if(datalist.getRecords().size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /** 分页查询
     * 根据类别ids查询绣字颜色+分页
     * @return
     */
    @PostMapping(value = "/query_xiuziColorPageList")
    public JSONObject query_xiuziColorPageList(
            @RequestParam(name="category_ids") String category_ids,
            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            String code){
        System.out.println("传进来的类别IDS是空的？=="+category_ids);
        JSONObject obj = new JSONObject();//返回对象
        String pinglei_id = "";
        //拿到类别ids
        String pingleis[] = category_ids.split(",");
        for (String s:pingleis){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==3){
                    pinglei_id = categoryInfo.getId().toString();
                    break;
                }
            }
        }
        Page<EmbroideredColorInfo> page = new Page<EmbroideredColorInfo>(pageNo, pageSize);
        System.out.println("拿到的品类id=="+pinglei_id);
        IPage<EmbroideredColorInfo> datalist = logicService.query_xiuziColorpageList(page,pinglei_id,code);
        if(datalist.getRecords().size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /**
     * 根据查类别id查询赋值产品名称
     * @return
     */
    @PostMapping(value = "/query_productName_categoryids")
    public JSONObject query_productName_categoryids(String category_ids){
        JSONObject obj = new JSONObject();//返回对象
        String productname="";
        String categoryids[] = category_ids.split(",");
        for (String s:categoryids){
            CategoryInfo categoryInfo = logicService.query_categoryDetailInfo(s);
            if(categoryInfo!=null){
                if(categoryInfo.getIsType()==2){
                    productname = categoryInfo.getCategoryName()+categoryInfo.getCategoryCode();
                    break;
                }
            }
        }
        obj.put("code", 0);
        obj.put("msg", "查询成功");
        obj.put("data", productname);
        return obj;
    }

    /**
     * 用户协议详情
     * type:0用户协议，1参照表
     * @return
     */
    @PostMapping(value = "/query_agreementDetail")
    public JSONObject query_agreementDetail(@RequestParam(name="msg_id") String msg_id,
                                            @RequestParam(name="type") String type){
        JSONObject obj = new JSONObject();//返回对象
        AgreementInfo datalist = logicService.query_userXieyiDetail(msg_id,type);
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /**
     * 根据产品id查询产品里面的面料
     * @return
     */
    @GetMapping(value = "/query_fabricodeDetailByid")
    public JSONObject query_productDetailByid(String product_id){
        JSONObject obj = new JSONObject();//返回对象
        ProductInfo datalist = logicService.query_productDetail(product_id);
        String fabric_code = "暂无";
        if(datalist != null){
            if(datalist.getFabricIds() !=null && !"".equals(datalist.getFabricIds())){
                String fabricIds[] = datalist.getFabricIds().split("/");
                if(fabricIds[0] != null && !"".equals(fabricIds[0])){
                    FabricInfo fabricInfo = logicService.query_fabricDetailInfo(fabricIds[0]);
                    if(fabricInfo!=null){
                        fabric_code=fabricInfo.getFabricCode();
                    }
                }
            }
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", fabric_code);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", fabric_code);
            return obj;
        }
    }

    /**
     * 根据用户id扎到公司再统计整个公司的退款金额
     * @return
     */
    @GetMapping(value = "/query_countRefundmoney")
    public JSONObject query_countRefundmoney(String token){
        JSONObject obj = new JSONObject();//返回对象
        MlccUserInfo userInfo = userservice.queryUserinfoByusername(token, 3);
        if (userInfo == null) {
            obj.put("code", 4);
            obj.put("msg", "token已失效，请重新登录");
            return obj;
        }
        //拿到用户id找公司
        List<RefundMoneyInfo> refundMoneyInfo = logicService.query_RefundMoneyInfo(userInfo.getCompanyuserId());
        String zui_money = "0";
        DecimalFormat df = new DecimalFormat("0.00");
        double money = 0.00;
        if(refundMoneyInfo.size() > 0){
            for (int i=0;i<refundMoneyInfo.size();i++){
                if(refundMoneyInfo.get(i).getReturnMoney()!=null && !"".equals(refundMoneyInfo.get(i).getReturnMoney())){
                    money+=Double.parseDouble(refundMoneyInfo.get(i).getReturnMoney());
                }
            }
            zui_money = df.format(money);
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", zui_money);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", zui_money);
            return obj;
        }
    }

    /**
     * 微信订单号查询微信订单的详情
     * @return
     */
    @GetMapping(value = "/query_wxStatusDetailBywxSn")
    public JSONObject query_wxStatusDetailBywxSn(String wx_out_orderSn){
        JSONObject obj = new JSONObject();//返回对象
        WxOrderStatus datalist = logicService.query_WxOrderStatusDetailBysn(wx_out_orderSn);
        if(datalist!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
            return obj;
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
            return obj;
        }
    }

    /**
     * 个订下面-复制产品信息
     * @return
     */
    @PostMapping(value = "/copy_singleorder_products")
    @Transactional(rollbackFor = Exception.class)
    public JSONObject post_copy_singleorder_products(ProductInfo productInfo){
        JSONObject obj = new JSONObject();//返回对象
        try {
            MlccUserInfo userInfo = userservice.queryUserinfoByusername(productInfo.getToken(), 3);
            if (userInfo == null) {
                obj.put("code", 4);
                obj.put("msg", "token已失效，请重新登录");
                return obj;
            }
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Long startTs = System.currentTimeMillis(); // 当前时间戳
            //8位随机数
            int random=new Random().nextInt(100000)+1;//为变量赋随机值1-99999999;
            int random2=new Random().nextInt(1000)+1;
            String productSn = "S-"+startTs.toString()+random2;
            String productId = startTs.toString()+random;

            String plateId="",pingle_id="",gongyi_id="",old_order_sn="",template_sn="";
            double lost_price1=0.00;
            //根据产品id查询产品详情
            ProductInfo old_productInfo1 = logicService.query_productDetail(productInfo.getId());
            if(old_productInfo1!=null){
                //转移产品信息
                productInfo.setProductName(old_productInfo1.getProductName()+"-"+random2);
                productInfo.setProductImg(old_productInfo1.getProductImg());
                productInfo.setSex(old_productInfo1.getSex());
                productInfo.setProductType(0);//产品类型
                productInfo.setStatus(0);
                productInfo.setZhehouPrice(0.0);
                productInfo.setZheqianPrice(old_productInfo1.getZheqianPrice());//折前价格
                productInfo.setCategoryIds(old_productInfo1.getCategoryIds());
                productInfo.setFabricIds(old_productInfo1.getFabricIds());
                productInfo.setXiuziPriceId(old_productInfo1.getXiuziPriceId());
                productInfo.setXiuziType(old_productInfo1.getXiuziType());
                productInfo.setXiuziWeizhi(old_productInfo1.getXiuziWeizhi());
                productInfo.setXiuziImg(old_productInfo1.getXiuziImg());
                productInfo.setXiuziColor(old_productInfo1.getXiuziColor());
                productInfo.setXiuziHeight(old_productInfo1.getXiuziHeight());
                productInfo.setZidingyiImg(old_productInfo1.getZidingyiImg());
                productInfo.setXiuziZiti(old_productInfo1.getXiuziZiti());
                productInfo.setXiuziOneNeirong(old_productInfo1.getXiuziOneNeirong());
                productInfo.setXiuziTwoNeirong(old_productInfo1.getXiuziTwoNeirong());
                productInfo.setZhuangseIds(old_productInfo1.getZhuangseIds());
                productInfo.setButtonsIds(old_productInfo1.getButtonsIds());
                productInfo.setLibuId(old_productInfo1.getLibuId());
                productInfo.setDilinliId(old_productInfo1.getDilinliId());
                productInfo.setRemark(old_productInfo1.getRemark());
                productInfo.setNumbers(1);
                productInfo.setFabricRemark(old_productInfo1.getFabricRemark());
                productInfo.setOrderSn(old_productInfo1.getOrderSn());//赋值订单编号
                productInfo.setTemplateSn(old_productInfo1.getTemplateSn());//赋值模板编号
                old_order_sn = old_productInfo1.getOrderSn();
                template_sn = old_productInfo1.getTemplateSn();

                /**赋值产品的价格*/
//                if (old_productInfo1.getCategoryIds() != null && !"".equals(old_productInfo1.getCategoryIds())) {
//                    String pinglei[] = old_productInfo1.getCategoryIds().split(",");
//                    for (String s:pinglei){
//                        //拿到类别名称和价格
//                        CategoryInfo categoryInfodetail = logicService.query_categoryDetailInfo(s);
//                        if(categoryInfodetail!=null){
//                            if(categoryInfodetail.getIsType()==3){
//                                plateId = categoryInfodetail.getId().toString();//拿到版号
//                            }
//                            if(categoryInfodetail.getIsType()==2){
//                                pingle_id = categoryInfodetail.getId().toString();//拿到品类id
//                            }
//                            if(categoryInfodetail.getIsType()==4){
//                                gongyi_id = categoryInfodetail.getId().toString();//拿到工艺id
//                            }
//                            /**默认0：表示订单里面的款式工艺，2表示品类，3版号,4工艺*/
//                            if(categoryInfodetail.getIsType()==4){
//                                String category_code = categoryInfodetail.getCategoryCode();//拿到工艺的编号
//                                //根据编号和上级品类id查询
//                                CategoryInfo categoryInfodetail2 = logicService.query_categoryDetailBytop_id(pingle_id,category_code);
//                                //拿到工艺id查询价格体系表
//                                PriceSystemPinleiInfo priceSystemPinleiInfo = logicService.query_pricesysytemDetail(categoryInfodetail2.getId().toString(),"0","1");
//                                if(priceSystemPinleiInfo!=null){
//                                    //拿到价格体系id
//                                    String price_systemId = priceSystemPinleiInfo.getId().toString();
//                                    //拿到体系主键id查询价格区间
//                                    List<PriceSystemQujianInfo> qujian_pricelist = logicService.query_pricequjian(price_systemId);
//                                    if(qujian_pricelist.size()>0){
//                                        for(int i=0;i<qujian_pricelist.size();i++){
//                                            if(qujian_pricelist.get(i).getMinNumbers()<=1 && qujian_pricelist.get(i).getMaxNumbers()>=1){
//                                                lost_price1+=Double.parseDouble(qujian_pricelist.get(i).getPrice());//产品售价
//                                            }
//                                        }
//                                    }else {
//                                        System.out.println("没有没有适合的价格区间=");
//                                    }
//                                }else {
//                                    System.out.println("没有设置价格体系="+categoryInfodetail.getIsType());
//                                }
//                            }
//                        }
//                    }
//                }
//                DecimalFormat df = new DecimalFormat("0.00");
//                productInfo.setZheqianPrice(Double.parseDouble(df.format(lost_price1)));

                /**赋值产品里面的尺寸信息*/
                if(old_productInfo1.getBodySizeIds()!=null && !"".equals(old_productInfo1.getBodySizeIds())){
                    //获取前端传过来的尺寸ids
                    String oldbody_sizes = old_productInfo1.getOldbodySizeIds();
                    productInfo.setBodySizeIds(old_productInfo1.getBodySizeIds());
                    productInfo.setOldbodySizeIds(oldbody_sizes);//变化之前的
                    //拿到前端传入的尺寸值尚未变化之前的
                    String size1[] = oldbody_sizes.split(",");
                    for (String s:size1){
                        String size2[] = s.split("/");
                        List<BodySizeInfo> bodySizeInfos = logicService.query_bodySizeinfo_productid(productId,size2[0],size2[1]);
                        if(bodySizeInfos.size()<=0){
                            logicService.add_Order_sizeInfo(productId,size2[0],size2[1],"0",new Date());
                        }
                    }
                }
            }
            //赋值产品货号
            productInfo.setProductCode(productSn);
            //赋值产品id
            productInfo.setId(productId);
            //赋值用户id
            productInfo.setUserId(userInfo.getId().toString());
            //添加产品
            int code = logicService.insert_products(productInfo);
            int code2=0,code3=0;
            //根据订单编号查询订单详情
            SingleOrderInfo singleOrderInfo = logicService.query_signorder(old_order_sn);
            if(singleOrderInfo!=null){
                //修改订单里面的产品
                String chanpin_ids = singleOrderInfo.getChanpingIds()+","+productId;
                code2 = logicService.update_single_order_products(chanpin_ids,old_order_sn);
            }
            //根据订单编号查询模板详情
            TemplateRecordInfo templateRecordInfo = logicService.query_templateRecordInfo(template_sn);
            if(templateRecordInfo!=null){
                //修改模板里面的产品
                String chanpin_ids = templateRecordInfo.getChanpinIds()+","+productId;
                code3 = logicService.update_single_template_products(chanpin_ids,template_sn);
            }
            if(code>0 && code2>0 && code3>0){
                obj.put("code", 0);
                obj.put("msg", "产品复制成功!");
                return obj;
            }else {
                obj.put("code", 1);
                obj.put("msg", "复制产品失败");
                return obj;
            }
        } catch (Exception e) {
            System.out.println("Exception=="+e.toString());
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            obj.put("code", 2);
            obj.put("msg", "系统错误：复制产品失败，请重新创建");
            return obj;
        }
    }


    /**
     * 查询商品详情
     * @return
     */
    @PostMapping(value = "/query_goods_detail")
    public JSONObject query_goods_detail(String goods_id){
        JSONObject obj = new JSONObject();//返回对象
        ThirdGoodsInfo datainfo = logicService.query_goodsDetailByid(goods_id);
        if(datainfo!=null){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datainfo);
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无此商品");
            obj.put("data", datainfo);
        }
        return obj;
    }
    /**
     * 查询商品的阶梯价
     * @return
     */
    @PostMapping(value = "/query_goods_rungprice")
    public JSONObject query_goods_rungprice(String series_id){
        JSONObject obj = new JSONObject();//返回对象
        List<ThirdGoodsLadderPrice> datalist = logicService.query_rungpricedatalist(series_id);
        if(datalist.size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
        }
        return obj;
    }
    /**
     * 根据商品id查询商品下面的规格
     * @return
     */
    @PostMapping(value = "/query_goods_Specifications")
    public JSONObject query_goods_Specifications(String goods_id){
        JSONObject obj = new JSONObject();//返回对象
        List<ThirdGoodsSpecifications> datalist = logicService.query_Specificationsdatalist(goods_id);
        if(datalist.size()>0){
            for (int i=0;i<datalist.size();i++){
                datalist.get(i).setBuynum(0);
            }
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
        }
        return obj;
    }
    /**
     * 根据商品id查询商品下面的参数
     * @return
     */
    @PostMapping(value = "/query_goods_Parameter")
    public JSONObject query_goods_Parameter(String goods_id){
        JSONObject obj = new JSONObject();//返回对象
        List<ThirdGoodParameter> datalist = logicService.query_Parameterdatalist(goods_id);
        if(datalist.size()>0){
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", datalist);
        }else {
            obj.put("code", 1);
            obj.put("msg", "暂无数据");
            obj.put("data", datalist);
        }
        return obj;
    }

    /**
     * 根据商品id、商品系列id、和购买数量获取价格查询商品下面的参数
     * @return
     */
    @PostMapping(value = "/query_goods_buyMoney")
    public JSONObject query_goods_buyMoney(String series_id, String goods_id, String buysum){
        JSONObject obj = new JSONObject();//返回对象
        DecimalFormat df = new DecimalFormat("0.00");
        //声明最终价格
        String lost_price = "0.00";
        double sumprice = 0.00;
        //根据商品id判断该商品是否是主推商品
        ThirdGoodsInfo datainfo = logicService.query_goodsDetailByid(goods_id);
        if(datainfo.getIsMain()==0){
            //根据系列id查询价格区间
            List<ThirdGoodsLadderPrice> datalist = logicService.query_rungpricedatalist(series_id);
            if(datalist.size()>0){
                for (int i=0;i<datalist.size();i++){
                    if(Double.parseDouble(datalist.get(i).getMin())<=Double.parseDouble(buysum) && Double.parseDouble(datalist.get(i).getMax())>=Double.parseDouble(buysum)){
                        sumprice = Double.parseDouble(datalist.get(i).getPrice()) * Double.parseDouble(buysum);
                        break;
                    }
                }
                lost_price = df.format(sumprice);
                obj.put("code", 0);
                obj.put("msg", "查询成功");
                obj.put("data", lost_price);
            }else {
                obj.put("code", 1);
                obj.put("msg", "暂无数据");
                obj.put("data", lost_price);
            }
        }else {//主推商品
            sumprice = Double.parseDouble(datainfo.getPrice()) * Double.parseDouble(buysum);
            lost_price = df.format(sumprice);
            obj.put("code", 0);
            obj.put("msg", "查询成功");
            obj.put("data", lost_price);
        }
        return obj;
    }

}
